2

jqGrid にはプロパティloadonce:trueがあり、最初のページ レコードのみを取得しています。2 ページ目と 3 ページ目のレコードを取得するにはどうすればよいですか。

コード:

$(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

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 にあり、ページのようなページが必要です。 :15 したがって、2 番目の呼び出しには実際のページが含まれます。これは、2 番目の呼び出しで重要なことです。ページが正しいことを確認するために 2 回の呼び出しが必要なだけです。この例では、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 に答える