Reputation: 263
We have an issue when no values are returned from Jqgrid. In this case next button of pager (jqGrid) is enabled. We have to disable it when grid is empty. Please help me in finding a solution.
Upvotes: 1
Views: 1236
Reputation: 85
loadComplete: function (data) {
var page = $('#mygrid').jqGrid('getGridParam', 'page');
var lastpage = $("#mygrid").getGridParam('lastpage');
//note: you can also get record count via data.records or data.rows.length in this function
if (lastpage > page) {
$('#next_mygridpager').removeClass('ui-state-disabled');
$('#last_mygridpager').removeClass('ui-state-disabled');
} else {
$('#next_mygridpager').addClass('ui-state-disabled');
$('#last_mygridpager').addClass('ui-state-disabled');
}
}
I believe this is a more complete solution because you also do not want the next and last button appear when there are no more pages to move forward.
Upvotes: 0
Reputation: 3091
To set the next button as disabled you can do the following:
$('#next_' + yourgridid + '_pager').addClass('ui-state-disabled');
To re-enable the button do:
$('#next_' + yourgridid + '_pager').removeClass('ui-state-disabled');
I suggest doing this in the loadComplete(data) event.
$("#yourgridid").jqGrid({
...
loadComplete: function(data){
var records = $('#yourgridid').jqGrid('getGridParam', 'reccount');
//note: you can also get record count via data.records or data.rows.length in this function
if (records > 0) {
$('#next_' + yourgridid + '_pager').removeClass('ui-state-disabled');
} else {
$('#next_' + yourgridid + '_pager').addClass('ui-state-disabled');
}
},
...
});
Upvotes: 2