简体   繁体   中英

jqgrid paging repeats the same rows

i am using jqgrid on asp.net mvc.

my view:

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

    });

My controller:

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

Question: My problem is that after each post-back(if i click next on the paging) the rows in the grid never gets updated, the screenshot shows it updates the page no, but still i get the first 10 rows of the grid,it never gets updated. let me know if you don't understand my question.


在此处输入图片说明

It looks like you're not using the page argument in your controller and getting the same list each time. You could do something like this:

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

I'm assuming rows is the number of rows per page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM