I want to use a custom property of jqgrid to persist some ASP.NET session value on the page, but cannot seem to get it working.
The grid is defined as below, with a custom property called "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!"
});
In the Controller, I set the value for MyVariable and return as Json data, hoping to persist the value on the grid:
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);
}
Now try to access this variale after the page loaded.
var $grid = $('#myGrid');
alert($grid.jqGrid('getGridParam', 'MyVariable'));
It always shows "Hello World", not "Hello Controller!". Does this mean the custom property can not be changed after grid is loaded?
Secondly, in this example if the user selects the CUSTOMERTYPE column header to filter the data, how do I get that filtered criteria value?
I am new to jqGrid and it's maddening to get the simple thing to work. Any help is really appreciated!