簡體   English   中英

jqgrid分頁重復相同的行

[英]jqgrid paging repeats the same rows

我在asp.net mvc上使用jqgrid。

我的觀點:

        $("#phoneGrid").jqGrid({
        url: '/Demo/_PhoneChangeData',
        datatype: 'json',
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
        serializeGridData: function (postData) {
            if (postData.searchField === undefined) 
               postData.searchField = null;
            if (postData.searchString === undefined) 
               postData.searchString = null;
            if (postData.searchOper === undefined) 
               postData.searchOper = null; 
            return JSON.stringify(postData);
        },
        jsonReader: {
            root: "rows", 
            page: "page",
            total: "total",
            records: "records",
            cell:"cell",
            id: "id" 
        },
        postData:
        {
            accountNumber: "@Model.AccountNumber",
        },
        autoWidth: true,
        shrinkToFit: false,
        mtype: 'POST',
        colNames: ['Phone Number', 'Update Date', 'Update Time'],
        colModel: [
         { name: 'PhoneNumber', width:100, align: 'left' },
         { name: 'UpdateDate', width: 100, align: 'left' },
         { name: 'UpdateTime', width: 100, align: 'left' }],
        rowNum: 10,
        rowList: [], 
        pager: "#pagerphonedetail",
        viewrecords: true, 
        rownumbers: true,
        pgtext: null, 
        width: 346,
        height: 232

    });

我的控制器:

public ActionResult _PhonePopupChangeData(string accountNumber, 
    int page, int rows, string sidx, string sord,
    bool _search, string searchField, string searchOper, string searchString)
    {
        var phdetail = query.GetPhoneUpdHistory(accountNumber);// returns a list

        int recordsCount =  phdetail.Count;

        var viewData = phdetail.Select((p, index) => new TableRow
        {
            id = index + 1,
            cell = new List<string> {
                p.PhoneNumber,  p.UpdateDate, p.UpdateTime
            }
        }).ToArray();
        var jsonData = new
        {
            total = (recordsCount + rows - 1) / rows,
            page = page,
            records = recordsCount,
            rows = viewData
        };

        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }

問題:我的問題是,每次回發后(如果我單擊分頁上的下一步),網格中的行將永遠不會更新,屏幕截圖顯示它更新了頁面編號,但是我仍然得到網格的前10行,它永遠不會更新。 如果您不明白我的問題,請告訴我。


在此處輸入圖片說明

似乎您沒有在控制器中使用page參數,而是每次都獲得相同的列表。 您可以執行以下操作:

var viewData = phdetail.Skip(rows*(page-1)).Take(rows).Select((p, index) 
    => new TableRow {
        id = index + 1,
        cell = new List<string> {
            p.PhoneNumber,  p.UpdateDate, p.UpdateTime
        }
    }).ToArray();

我假設行是每頁的行數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM