jqgrid分页重复相同的行

时间:2013-02-06 23:10:20

标签: c# jquery ajax asp.net-mvc jqgrid

我在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行,它永远不会更新。如果你不理解我的问题,请告诉我。


enter image description here

1 个答案:

答案 0 :(得分:1)

看起来你没有在你的控制器中使用页面参数并且每次都获得相同的列表。你可以这样做:

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

我假设行是每页的行数。