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