这是问题所在,当我定义ddl(下拉列表或选择框)时,我不知道选定的值。当用户编辑一行时,用户可以从列表中选择一个项目。但所选项目未设置。我想在用户单击按钮编辑行时设置选定的项目。无法从jqGrid中的单元格获取对象(jQuery)
正确的方法,我认为,是让时的jqGrid建成并设置选定值已创建的DDL。
$("#list").jqGrid({
datatype: 'clientSide',
colNames: ['Edit', 'Delete', 'Save', 'Cancel', 'Location'],
colModel: [
....
....
{ name: 'Location', index: 'Location', width: 90, editable: true, edittype: "select", editoptions: { value: SI:System Integration ; IM:Information Management ; IA:Industrial Automation ; CI:Custom Instrumentation}}]
});
当用户点击编辑按钮,我从DDL列表获取数据
var locationText = $("#list").getRowData(rowNum).Location;
locationText =
<SELECT id=1_Location class=editable><OPTION value="R ">Rochester</OPTION><OPTION selected value="MA ">Massachusetts</OPTION><OPTION value="DL ">Data Librarian</OPTION><OPTION value="Buff ">Buffalo/Niagara Falls</OPTION><OPTION value="Bing ">Binghamton/Owego/Southern Tier</OPTION><OPTION value="Other ">All other locations</OPTION><OPTION value="Alb ">Albany and all points East</OPTION><OPTION value=""></OPTION></SELECT>
而是从细胞中的jqGrid我宁愿得到的DOM元素DDL对象获取的数据。
其他的想法,我有,但不认为这是正确的,是用locationText并用它来创建一个新的DDL DOM元素。
这样的事情。
var locationTmp2 = document.createElement("select");
locationTmp2.innerHTML = locationText;
or
locationTmp2.text= locationText;
有没有一种简单的方法来做我想做的事情。 我知道我可以创建一个新的DOM选择元素,然后每个选项添加到它,这样
//populate and set the selected item for locations.
var locationSelect = document.createElement("select");
var arrayLocations = ('R:Rochester;MA:Massachusetts;DL:Data Librarian;Buff:Buffalo/Niagara Falls;Bing :Binghamton/Owego/Southern Tier;Other:All other locations;Alb:Albany and all points East;').split(";");
for (var i = 0; i < arrayLocations.length - 1; i++) {
var optionItem = document.createElement("option");
optionItem.value = trim(arrayLocations[i].split(":")[0]);
optionItem.text = trim(arrayLocations[i].split(":")[1]);
//check if this should be the selected item.
if (arrayLocations[i].indexOf(rowData.Location) != -1)
optionItem.selected = true;
locationSelect.add(optionItem);
}
但应该有抢从jqGrid的整个DOM元素的方式。
感谢
jqGrid有内置的行编辑功能吗?当用户点击编辑时是否会为您创建下拉菜单,或者您是否必须自己做这些操作? – 2009-01-08 15:47:58