0

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 ?

dsi
  • 3,199
  • 12
  • 59
  • 102
  • Do you use "local" `datatype` or not? How you delete the rows (which API)? Do you send any data to the server during deleting? The main difference is that the number of row can be changed *on the server*. So during deleting of records locally one makes *refresh* of data and loads the current number of rows on the server. During the time some other rows could be added or deleted. – Oleg Sep 24 '14 at 06:55
  • sorry for less details. I do custom delete. On click of "hyper link", call the javascript funciton which makes ajax call to server and delete the record. AFter that, i do referesh the grid using `$("#GrdList").trigger('reloadGrid');` . Please guide how to change the page in case it is deleted. also, no records exists then just show label. I got `emptyrecords` but, it appears when page has no record (though header and pager appear). – dsi Sep 24 '14 at 07:08

1 Answers1

1

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798