In jqgrid, when there are 6 records (Paging 5).
So, first page has 5 records and second page has 1 record now, user has deleted 6th record (from page #2).
Then, grid still remains on page #2 and no rows exists on page 2 as its deleted. It does not look good when 5 records on page 1 and no records on page 2 though, page selection appeared on page 2.
Can you please guide how to solve that. i think, it should be move to earlier page (last page).
Also, related issue:
when all 6 records are deleted. then, grid still appear.
Insted of that, there should be some label message to appear as no records exists.
How to achieve this ?
You can use reccount
options which provides the number or records on the current page of the grid. If the number of records is 0 you can do additional action. For example you can trigger reloadGrid
with additional page
option (see the answer)
var $self = $(this), // or $("#gridId")
p = $self.jqGrid("getGridParam"), // get all parameters
newPage;
if (p.lastpage > 1) { // on the multipage grid
newPage = p.page; // the current page
if (p.reccount === 0 && p.page === p.lastpage) {
// if after deleting there are no rows on the current page
// which is the last page of the grid
newPage -= 1; // go to the previous page
}
// reload grid to show rows from the page with rows.
// depend on where you use the code fragment you could
// need reloading only in case
// p.reccount === 0 && p.page === p.lastpage
setTimeout(function () {
$self .trigger("reloadGrid", [{ page: newPage}]);
}, 50);
}
If you need to display some message text in the grid body you can follow the demo created for the answer. The demo just shows div with the message text in case of reccount === 0
.