我想使用 jqgrid 的自定义属性在页面上保留一些 ASP.NET 会话值,但似乎无法使其正常工作。
网格定义如下,带有一个名为“MyVariable”的自定义属性。
$("#myGrid").jqGrid({
url: RootAbsolutePath + "Customer/GetCustomerList",
datatype: "json",
mtype: 'POST',
page: 1,
rowNum: 10,
rowList: [10, 20, 30],
pager: $("#myPager"),
toppager: true,
colNames: column_names,
colModel: [
{ name: "CUSTOMERNUMBER", index: "CUSTOMERNUMBER", width: 150, align: "center", "formatter": customerEditLink },
{ name: "DEALERSHIPID", index: "DEALERSHIPID", width: 150, align: "center", stype: "select", searchoptions: { "value": dealerShopSelector} },
{ name: "IDENTITYNUMBER", index: "IDENTITYNUMBER", width: 150, align: "center" },
{ name: "CUSTOMERNAME", index: "CUSTOMERNAME", width: 150, align: "left" },
{ name: "CUSTOMERTYPE", index: "CUSTOMERTYPE", width: 120, align: "center", "stype": "select", "searchoptions": { "value": typeSelector} },
{ name: "MOBILE", index: "MOBILE", width: 120, align: "center" },
{ name: "ADDRESS", index: "ADDRESS", width: 400, align: "left" },
],
autowidth: true,
shrinkToFit: false,
height: "100%",
viewrecords: true,
hoverrows: true,
sortname: "CUSTOMERNAME",
sortorder: "asc",
MyVariable: "Hello World!"
});
在 Controller 中,我设置了 MyVariable 的值并作为 Json 数据返回,希望将值保留在网格上:
public JsonResult GetCustomerList()
{
var model = new someModel();
List<object> listOfObjects = new List<object>();
// do something with the model and get data into listOfObjects
var jsonData = new
{
total = model.TotalPages,
page = model.page,
records = model.totalRecords,
MyVariable = "Hello Controller!",
rows = listOfDataObjects
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
现在尝试在页面加载后访问此变量。
var $grid = $('#myGrid');
alert($grid.jqGrid('getGridParam', 'MyVariable'));
它总是显示“Hello World”,而不是“Hello Controller!”。这是否意味着加载网格后无法更改自定义属性?
其次,在此示例中,如果用户选择 CUSTOMERTYPE 列标题来过滤数据,我如何获得该过滤条件值?
我是 jqGrid 的新手,让简单的事情工作起来令人抓狂。非常感谢任何帮助!