我在服務器端使用C#生成列模型並將jSON傳遞到網格。現在我想要一列提供下拉功能。但它不工作了,這是我到目前爲止有:在jqgrid中設置C#下拉選項
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 + "}}"
};
這裏是我columnmodel類:
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);
}
}
我收到的下拉列中選擇,但它是空的,我試圖遵循解釋here ..any幫助格式?
你可以發佈你的JavaScript代碼和標記嗎? – testCoder
對帖子進行編輯。 – faizanjehangir