本文介绍了在jqgrid中,如何处理页面或网格上不存在任何记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jqgrid中,当有6条记录时(分页5).因此,第一页有5条记录,第二页现在有1条记录,用户已删除第6条记录(从第2页开始).然后,网格仍保留在页面#2上,并且由于删除而在页面2上没有行.当第1页上有5条记录而第2页上没有任何记录时,看起来并不好,第2页上出现了页面选择.

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).

另外,相关问题:当全部6条记录被删除时.然后,网格仍会出现.为此,应该出现一些标签消息,因为不存在任何记录.如何实现呢?

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 ?

推荐答案

您可以使用reccount选项在网格的当前页面上提供编号或记录 .如果记录数为0,则可以执行其他操作.例如,您可以使用其他page选项触发reloadGrid(请参见答案)

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);
}

如果您需要在网格主体中显示一些消息文本,则可以遵循答案创建的演示.在reccount === 0的情况下,该演示仅显示div和消息文本.

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.

这篇关于在jqgrid中,如何处理页面或网格上不存在任何记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 12:10