我在我的应用程序中使用easyui datagrid。如果没有返回记录,如何在表中显示消息(例如:没有找到记录!)?
$('#test').datagrid({ onLoadSuccess:function(data){ if(data.total == 0){ alert("No Records founds"); } } });
我在jeasyui论坛找到了一些解决方案。 请参考以下链接
根据链接,我在代码中进行了以下更改
$('#test').datagrid({ onLoadSuccess:function(data){ showGridMessage($('#test')); } }) function showGridMessage(target){ var opts = $(target).datagrid('options'); var vc = $(target).datagrid('getPanel').children('div.datagrid-view'); vc.children('div.datagrid-empty').remove(); if (!$(target).datagrid('getRows').length){ var d = $('').html('No Records Found').appendTo(vc); d.css({ position:'absolute', left:0, top:50, width:'100%', textAlign:'center' }); }else{ vc.children('div.datagrid-empty').remove(); } }
你需要做的是当你从数据库中选择数据时,你需要检查结果行是否大于0,如果它大于0,只需要在格式$sampledata[$i]['nameof_field1'] = $dataresult->column;
的数组中进行解析$sampledata[$i]['nameof_field1'] = $dataresult->column;
如果select中没有数据,则需要使用相同格式进行解析但空值$sampledata[0]['nameof_field1'] = '';
然后你可以尝试这个代码
onLoadSuccess:function(data){ if(data.nameof_field1==''){ alert("No Records founds"); } }
以上就是jQuery教程分享如果没有返回记录,如何在表中显示消息(例如:没有找到记录!)?相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/547985.html