解决方法
我正在寻找这个答案,并提出了以下解决方案,但我不是在与服务器交谈,所以我必须使用除’loadComplete’事件之外的东西.我联系到“gridComplete”事件,并检查是否有任何记录.如果没有,请显示您的空文本,否则隐藏它.
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 } }