当 jqGrid 为空时,我想在网格内显示单个空行,并显示没有任何数据的信息消息。这怎么可能?谢谢
最佳答案
我一直在寻找这个问题的答案并提出了以下解决方案,但我没有与服务器对话,所以我必须使用“loadComplete”事件之外的东西。我连接到“gridComplete”事件并检查是否有任何记录。如果不是,则显示您的空文本,否则将其隐藏。
<pre>jQuery('#test').jqGrid({
... // some settings
gridComplete: loadCompleteFunction,
emptyDataText:'There are no records. If you would like to add one, click the "Add New ..." button below.', // you can name this parameter whatever you want.
... // more settings
});
function LoadComplete()
{
if ($('test').getGridParam('records') == 0) // are there any records?
DisplayEmptyText(true);
else
DisplayEmptyText(false);
}
function DisplayEmptyText( display)
{
var grid = $('#test');
var emptyText = grid.getGridParam('emptyDataText'); // get the empty text
var container = grid.parents('.ui-jqgrid-view'); // find the grid's container
if (display) {
container.find('.ui-jqgrid-hdiv, .ui-jqgrid-bdiv').hide(); // hide the column headers and the cells below
container.find('.ui-jqgrid-titlebar').after('' + emptyText + ''); // insert the empty data text
}
else {
container.find('.ui-jqgrid-hdiv, .ui-jqgrid-bdiv').show(); // show the column headers
container.find('#EmptyData' + dataObject).remove(); // remove the empty data text
}
}
</pre>
关于javascript - 如何在jqGrid中显示没有任何数据的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1019155/