【问题标题】:Jqgrid Sorting not workingJqgrid排序不起作用
【发布时间】:2012-04-28 07:34:39
【问题描述】:

我用下面的代码创建了一个 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')
    });

【问题讨论】:

    标签: asp.net-mvc linq sorting jqgrid


    【解决方案1】:

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

    你只需改变“它”。根据您的按键操作

    【讨论】:

      【解决方案2】:

      雷克斯

      您的 colmodel 中缺少一个属性。

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

      { name: 'firstName', index: 'firstName', sortable: true, sorttype: "text", searchoptions: { sopt: ['eq', 'ne'] }, width: 180 }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多