2

在 jqGrid 中有属性loadonce:true那么我只得到第一页记录。我怎样才能得到第二页和第三页的记录。

代码:

$(function () {

        $("#pendingAppgrid").jqGrid({
            colNames: ['Name', 'Email'],
            colModel: [
                        { name: 'Name', index: 'Name', sortable: true, align: 'left', width: '200',
                            editable: false, edittype: 'text',search:true

                        },

                         { name: 'Email', index: 'Email', sortable: false, align: 'left', width: '200',
                             editable: false, edittype: 'text',search:true
                         },  
                  ],
            pager: jQuery('#pager'),
            sortname: 'Name',
            rowNum: 15,
            rowList: [10, 20, 25],
            sortorder: "desc",
            height: 345,
            ignoreCase: true,
            viewrecords: true,
            rownumbers: true,
            caption: 'Pending Approvals',
            width: 660,
            url: "@Url.Content("~/Home/PendingApprovals")",
            datatype: 'json',
            mtype: 'GET',
            loadonce: true
        })
        jQuery("#pendingAppgrid").jqGrid('filterToolbar', { searchOnEnter: true, enableClear: false });

    });

服务器代码

public ActionResult PendingApprovals(int page, int rows, string sidx, string sord)
        {

            //return View(GetPendingApprovals());
            int currentPage = Convert.ToInt32(page) - 1;
            int totalRecords = 0;
            List<ViewModels.Channel.UserChannels> lTemChannel = new List<ViewModels.Channel.UserChannels>();
            List<ViewModels.Channel.UserChannels> lstChannel = new List<ViewModels.Channel.UserChannels>();
            lTemChannel = GetPendingApprovals();
            foreach (ViewModels.Channel.UserChannels cha in lTemChannel)
            {
                ViewModels.Channel.UserChannels channelWithLogo = new ViewModels.Channel.UserChannels();
                channelWithLogo.ID = cha.ID;
                channelWithLogo.Name = cha.Name;
                channelWithLogo.Email = cha.Email;

                lstChannel.Add(channelWithLogo);
            }
            totalRecords = lstChannel.Count;
            var totalPages = (int)Math.Ceiling(totalRecords / (float)rows);
                lstChannel = lstChannel.ToList<ViewModels.Channel.UserChannels>();

            IPagedList<ViewModels.Channel.UserChannels> ilstChannel;
            switch (sord)
            {
                case "desc":
                    ilstChannel = lstChannel.OrderByDescending(m => m.Name).ToPagedList(page, rows);
                    break;
                case "asc":
                    ilstChannel = lstChannel.OrderBy(m => m.Name).ToPagedList(page, rows);
                    break;
                default:
                    ilstChannel = lstChannel.OrderBy(m => m.Name).ToPagedList(page, rows);
                    break;
            }

            var data = ilstChannel;

            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,

                rows = (from m in data
                        select new
                        {

                            id = m.ChannelID,
                            cell = new object[]
                           {
                               m.Name,
                               m.Email
                           }
                        }).ToArray()
            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }

在这里,我只得到第一页记录。我有更多的页面。搜索功能工作正常。问题是我只是第一页记录。没有得到其他页面记录。我怎样才能得到另一个页面记录。请帮忙。

4

2 回答 2

4

如果您使用jqGrid在第一次从网格加载数据后将loadonce:true数据类型参数更改为“本地”。所有下一个网格重新加载(排序、分页、过滤)都在本地工作。如果您想再次从服务器刷新网格数据,您应该将数据类型设置为其原始值(“ json ”或“xml”)。例如:

$("#pendingAppgrid").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

有关 jqGrid 选项的更多详细信息,请访问http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

于 2013-06-21T06:52:34.667 回答
1

问题很复杂,连评论都看完了,你需要恢复Jgrid的实际页面:

var llPage = $("#listaCfdi").jqGrid('getGridParam', 'page');
//1 but this page is not the page of the "pager" and is before to call the method that fill the jgrid again
//, so the page will change after to fill the grid, you must call "onPaging" to fill again the Jgrid, like this:

//2
, onPaging: function (pgButton) {
        FillAgainJgrid();
    }

并在 FillAgainJgrid(); (在此示例中)您需要再次调用其他方法,该方法将具有用户想要的“寻呼机”的真实页面,例如,jgrid 在 page:5 中,并且您想要 las 页面,类似于 page :15,所以第二次调用会有真正的页面,这是第二次调用的重要内容。只有它需要两次调用来确保页面是正确的。在这个例子中, FillAgainJgridEnsure(); 与 FillAgainJgrid() 完全相同;除了没有 onPaging 再次

//3. In the server side, the page you are passed to the method only will work in the first call, because have all the data
//, and all the pages, but in example in the second call with the page:3, the jgrid will lost all the real information about the size of page, and only will return page:3 like if was the only one, you need a trick like this
//, (they are two list, one with all the data, and then you will get only the page you need, and the second list will have all the other rows in empty
//, so in this way you will get always all the correct rows number of the query, you need Concat in this example because we need all the rows, and if you are filled with dataset, in the sql server you need to use union all) :

ENTIDADES.Cfdi[] resultadoDos = null; //This is the class to provide the correct number of rows

        //this is the query that always will have all the data
        resultado = new CLASES.DAL.Facturacion().ObtenerCfdiDisponibles(criteriosBusqueda);
        if (resultado.Length > 100)
        {
            resultadoDos = new ENTIDADES.Cfdi[resultado.Length - 100];
            for (int i = 0; i < resultado.Length - 100; i++)
            {
                ENTIDADES.Cfdi referenciaVacia = new ENTIDADES.Cfdi();
                resultadoDos[i] = referenciaVacia;
            }
        }
//Paging here, in the server size
        resultado = resultado.OrderBy(p => p.Cliente).Skip(((Convert.ToInt32(_Pagina)) - 1) * 100).Take(100).ToArray();
        if (resultadoDos != null) //if there are more that 100 rows, in this example
        {//concat the page and the fill data empty 
            resultado = resultado.Concat(resultadoDos).OrderByDescending(x => x.Cliente).ToArray();
        }

        regresar = Newtonsoft.Json.JsonConvert.SerializeObject(resultado);

//注意,不要忘记OrderByDescending(在这个例子中),因为它会首先显示填充​​了行的数据,100是页面的行数。

奥马尔·罗梅罗 墨西哥城

于 2016-11-07T23:10:54.210 回答