I was looking for answer to this one and came up with the following solution, but I'm not talking to the server, so I have to using something besides the 'loadComplete' event. I hooked into the 'gridComplete' event and check to see if there are any records. If not, display your empty text, otherwise hide it.
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
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…