0

我用下面的代码创建了一个 jqgrid,我成功地创建了 jqgrid 而没有排序。所以我修改了代码,但它没有对数据进行排序并显示以下错误,

'firstName' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 1.

控制器

public ActionResult GridData(string sidx, string sord, int page, int rows)
    {
        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        int totalRecords = db.customers.Count();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

        var _Customers = db.customers.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize).ToArray();

        var jsonData = new
        {
            total = (int)Math.Ceiling((float)totalRecords / (float)rows),
            page = page,
            records = totalRecords,
            rows = (from r in _Customers.AsEnumerable()
                    select new
                    {

                        id = r.id,
                        cell = new[] { "<input type='radio' style='cursor:pointer' class='view_Account'  name='selectedCall'  id='" + r.id + "' value='" + r.id + "' />", r.firstName, r.lastName }
                    }
                   ).ToArray()
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);

    }

看法

$("#list").jqGrid({
        url: '/Customer/GridData/',
        datatype: 'json',
        colNames: ['', 'FirstName', 'LastName'],
        colModel: [
        { name: 'ssss', width: 20, search: false },
                    { name: 'firstName', sortable: true, sorttype: "text", searchoptions: { sopt: ['eq', 'ne'] }, width: 180 },
                    { name: 'lastName', sortable: true, sorttype: "text", width: 183 }

                ],
        rowNum: 100,
        width: '200px',
        height: '100px',
        sortname: 'firstName',
        sortorder: "asc",
        pager: jQuery('#pager')
    });
4

2 回答 2

2

var _Customers = db.customers.OrderBy("it." + sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize).ToArray();

你只需改变“它”。按您的要求按钥匙工作

于 2012-11-03T04:00:39.950 回答
1

雷克斯

您的 colmodel 中缺少一个属性。

为了使排序工作,您需要添加一个索引,如下所示:

{ name: 'firstName', index: 'firstName', sortable: true, sorttype: "text", searchoptions: { sopt: ['eq', 'ne'] }, width: 180 }
于 2012-04-29T07:36:25.640 回答