我見過很多關於在視圖中設置colmodel的例子,但是我一直無法看到控制器代碼! 我正在嘗試這樣做,但安裝程序仍然錯誤。 我想達到這個縱隊隊形:MVC3 JQGrid從控制器動態設置colmodel
colModel:
[
{ name: 'ID', index: 'ID', hidden: true },
{ name: 'Votes', index: 'Votes', width: 100, align: 'left' },
{ name: 'Question', index: 'Question', width: 300, align: 'left' },
{ name: 'my_clickable_checkbox', index: 'my_clickable_checkbox',
sortable: true,
formatter: chkFmatter, formatoptions: { disabled: false }, editable: true,
edittype: "checkbox"
}
],
這是我在控制器試驗:
return Json(
new { colNames = new[] { "ID2", "Votes2", "Question2", "checkbox" },
colModel = new[] {
new { name = "ID", index = "ID", width = 0, formatter="",
edittype="", hidden = true },
new { name = "Votes", index = "Votes", width = 100, formatter="",
edittype="", hidden = false },
new { name = "Question", index = "Question", width = 300, formatter="",
edittype="", hidden = false },
new { name = "checkbox", index = "my_clickable_checkbox", width = 100,
formatter="chkFmatter", edittype="checkbox", hidden = false }
}
}, JsonRequestBehavior.AllowGet);
該陣列控制器的創建是逼着我有相同數量的屬性在所有行中。例如,我只需要隱藏ID
,但它迫使我爲所有其他列提供hidden
屬性。
第二個問題,我需要爲第四列調用js函數chkFmatter
。
我怎樣才能達到colModel形成控制器?
非常感謝。