我想使用jqgrid的自定義屬性來在頁面上保留一些ASP.NET會話值,但似乎無法使其工作。jqgrid的自定義屬性無法更改?
該網格定義如下,並具有名爲「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);
}
現在嘗試加載頁面後訪問此variale。
var $grid = $('#myGrid');
alert($grid.jqGrid('getGridParam', 'MyVariable'));
它總是顯示「Hello World」,而不是「Hello Controller!」。這是否意味着網格加載後無法更改自定義屬性?
其次,在本例中,如果用戶選擇CUSTOMERTYPE列標題來過濾數據,那麼如何獲得過濾的標準值?
我是jqGrid的新手,它很生氣地讓簡單的工作。任何幫助真的很感激!
對不起,正是應此loadComplete功能被添加到?我試圖添加到jqGrid,但拋出異常,沒有這樣的方法。 – user2361287 2013-05-08 09:38:53
@ user2361287:它是回調函數。您應該像jqGrid('colModel','datatype'等等)的其他選項一樣添加它。 – Oleg 2013-05-08 09:40:49
謝謝奧列格。我發現我的問題是我複製setGridparam。它應該是setGridParam。現在我接近解決我的問題,現在在網格上更新自定義屬性MyVariable。但我仍然需要在C#中的Controller類中獲取此變量。有沒有一種簡單的方法,而不通過URL參數,因爲這個變量可以包含許多特殊字符,並會使URL無效? – user2361287 2013-05-09 02:35:02