为了动态填充选择下拉列表,只需在创建 jqgrid 的上方创建一个变量。
var countries = $.ajax(
{url:'/Specimens/GetAreaStrList/',async: false,
success: function(data, result)
{
if (!result)
alert('Failure to retrieve the Countries.');
}
}
).responseText;
然后你填充网格
{name:'AreaID', index:'AreaID', width:150, align:'left', editable:true,
edittype:"select",editoptions:{size: 71} }
],
onSelectRow: function(id)
{
if(id && id !== lastsel2)
{
jQuery('#list').restoreRow(lastsel2);
jQuery('#list').editRow(id, true);
lastsel2 = id;
}
},
loadComplete: function()
{
jQuery('#list').setColProp('AreaID', {editoptions: {value: countries}});
},
和控制器中的代码:
public ActionResult GetAreaStrList() { return Content("171:Russian Federation;86:Another Country"); }
我从这个博客中得到了启发:http:
//geekswithblogs.net/renso/archive/2009/07/02/jqgrid-dynamically-loading-select-options.aspx