In jqgrid, how to handle when no records exists on page or grid

▼魔方 西西 提交于 2019-12-12 02:53:10

问题


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 ?


回答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.



来源:https://stackoverflow.com/questions/26010232/in-jqgrid-how-to-handle-when-no-records-exists-on-page-or-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!