如果没有返回记录,如何在表中显示消息(例如:没有找到记录!)?
我在我的应用程序中使用easyui datagrid。如果没有返回记录,如何在表中显示消息(例如:没有找到记录!)?
$('#test').datagrid({ onLoadSuccess:function(data){ if(data.total == 0){ alert("No Records founds"); } } });
我在jeasyui论坛找到了一些解决方案。 请参考以下链接
http://www.jeasyui.com/forum/index.php?topic=1881.msg4135#msg4135
根据链接,我在代码中进行了以下更改
$('#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"); } }