我想在我的jqgrid的DropDown中加载我的服务器数据。我的代码,jqgrid colmodel editoptions加载json结果
更新的代码:
public ActionResult GetUnit()
{
List<UnitModel> getUnitValues = new List<UnitModel>();
//ToDo db code
Dictionary<int, string> unitValues = new Dictionary<int, string>();
unitValues = getUnitValues.ToDictionary(x => x.UnitID, x => x.UnitDesc);
unitValues.Add(4, "Unit2/3");
unitValues.Add(1, "Unit1");
unitValues.Add(2, "Unit2");
unitValues.Add(3, "Unit3");
return Json(unitValues, JsonRequestBehavior.AllowGet);
}
我的jqGrid:
colModel: [...
{
name: 'UnitID', index: 'UnitID', editable: true, edittype: 'select', width: "200",
formatter: 'select', editoptions: { value: unitslist},
editrules: { custom: true, custom_func: dupicateRecordValidation
}
},
...],
beforeProcessing: function() {
$.ajax({
url: '/Home/GetUnit/',
dataType: 'json',
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
$.map(data, function (value, key) {
unitsList += '"' + value + '"' + ':' + '"' + key + '"' + ',';
});
unitsList += '}';
alert(unitsList);
}
});
},
但是,这是行不通的。 jqgrid DropDown列加载空单元格。我错过了什么吗?这是正确的方法吗?请建议是否有任何替代方法来加载jqgrid与服务器数据的下拉列表,并选择该行的默认值。谢谢。
注:我使用jQuery的jqGrid v4.4.4的Visual Studio
一如既往,你是如此有帮助。感谢您的反馈意见。我试着按照你的建议,但仍然得到了内联jqgrid下拉列表的空单元格。请找到更新的代码,并建议我。谢谢。 – Kavitha
@Kavitha:对不起,但你误解了我的建议。您应该**不**在'beforeProcessing'内部进行额外的Ajax调用。 'url'的主要答案(用于填充网格的主要数据)应该包含当前提供'GetUnit'的信息。请仔细阅读[答案](http://stackoverflow.com/a/19427444/315935),我在当前的答案中引用了你的问题。查看JSON响应中的'colModelOptions'部分以及相应的C#代码。 – Oleg
你真棒。非常感谢。它的工作完美。您的意见非常有帮助。 – Kavitha