我正在使用 C# 在服务器端生成列模型并将 jSON 传递给网格。现在我想要一列提供下拉功能。但它没有成功,这是我到目前为止所拥有的:
StringBuilder deptDetails = new StringBuilder();
foreach (Department dept in departmentList)
{
deptDetails.Append(dept.DepartmentID);
deptDetails.Append(":'");
deptDetails.Append(":'" + dept.DepartmentName + "',");
deptDetails.Append(',');
}
deptDetails.Length -= 1;
colModel[i] = new ColumnMod
{
name = selectedItems[i].ToString(),
index = selectedItems[i].ToString(),
width = 100,
editable = true,
edittype = "select",
align = "left",
editoptions="{value:{" + deptDetails + "}}"
};
这是我的列模型类:
public class ColumnMod
{
public string name { get; set; }
public string index { get; set; }
//public Boolean key { get; set; }
public Int32 width { get; set; }
public Boolean editable { get; set; }
public string edittype { get; set; }
//public Boolean sortable { get; set; }
public string align { get; set; }
//public Boolean hidden { get; set; }
public string editoptions { get; set; }
}
编辑:
这是我的 JS 代码:
$grid.jqGrid({
colNames: selectedItems,
colModel: columnSelected,
sortname: selectedValues[0],
sortorder: "asc",
editurl: 'url',
cellsubmit: 'clientArray',
cellEdit: true,
rowNum: 5000,
rownumbers: true,
rownumWidth: 30,
autowidth: true,
shrinkToFit: true,
gridview: true,
pager: '#gridPager',
viewrecords: true,
recordtext: "Total Rows: {2}",
jsonReader: {
root: "rows",
page: "page",
total: "totalpages",
records: "totalrecords",
cell: "cell",
id: selectedValues[0], //index of the column with the PK in it
userdata: "userdata",
repeatitems: true
},
prmNames: {
rows: "numRows",
page: "page",
sort: "sortField",
order: "sortOrder"
},
datatype: function (postdata) {
if (lastSortField != postdata.sortField || lastSortOrder != postdata.sortOrder)
{ if (!$('#btnValidate').is(':disabled')) {
lastSortField = postdata.sortField;
lastSortOrder = postdata.sortOrder;
}
}
}
这就是我在 columnModel 中获得价值的方式:
function getSelectedColumnsJSON(selectedValues) {
try {
$.ajax({
type: "POST",
url: window.location.protocol + '//' + window.location.host + window.location.pathname + "/getSelectedColumnsJSON",
data: $.toJSON({
selectedItems: selectedValues
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data, status) {
if (data.d)
columnSelected = data.d;
},
error: function (error) {
ShowMessage(error.responseText);
}
});
}
catch (ex) {
ShowMessage(ex.message);
}
}
我在列中得到下拉选择,但它是空的,我试图按照这里解释的格式..有什么帮助吗?