I want to use JSON data in select box in JqGrid
public 开发者_如何学PythonActionResult GetKpiList()
{
for (int i = 0; i < 5; i++)
{
JqGrid.Row row = new JqGrid.Row();
row.id = i;
row.cell.Add(i.ToString());
row.cell.Add("Kpi - " + i.ToString());
grid.rows.Add(row);
}
grid.page = 1;
grid.records = 5;
grid.total = 5;
return Json(grid, JsonRequestBehavior.AllowGet);
}
I have this test function, to return, id and value pair for the selectbox i want to use in jqgrid.
How can i use this values to populate selectbox ?
{ name: 'kpiName', index: 'kpiName', width: 300, align: "right", editable: true, edittype: 'select', editoptions: { dataUrl: '/KpiSet/GetKpiList/' }
this does not works.
If you provided the sample JSON it produces when you visit the URL, we might get a better idea about how it is being shaped. (or you might add another tag which describes the language you are using, apparently some .NET language I guess).
According to http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#select , it looks like your Ajax URL must be returning a <select/>
element, and not JSON. If you don't want to change the server-side script, you could either serialize it to a string (option 1: editoptions: { value: “FE:FedEx; IN:InTime; TN:TNT” }
) or shape it so that you can add your object: editoptions:{value:{1:'One',2:'Two'}}
精彩评论