1 回答
当前版本的 jqGrid 不适<optgroup>
用于<select>
.
我发现<optgroup>
在某些情况下使用 可能会有所帮助。所以我稍微调试了一下jqGrid代码,发现只需要更改jqGrid的两行代码( jqGrid 4.1.1的第143-144行grid.inlinedit.js
或jquery.jqGrid.src.js
jqGrid 4.1.1的第8262-8263行)
tmp[nm] = $("select>option:selected",this).val();
tmp2[nm] = $("select>option:selected", this).text();
至
tmp[nm] = $("select>option:selected,select>optgroup>option:selected",this).val();
tmp2[nm] = $("select>option:selected,select>optgroup>option:selected",this).text();
或者只是为了
tmp[nm] = $("select option:selected",this).val();
tmp2[nm] = $("select option:selected",this).text();
解决问题。
如果需要支持具有multiple: true
属性的选择:
应该以与上述相同的方式修改. 要使带有属性的 jqGrid 与属性一起使用,必须再修复. 一需要改变grid.inlinedit.js
"select>option:selected"
multiple: true
dataUrl
grid.inlinedit.js
if(cm[i].edittype == "select" && cm[i].editoptions.multiple===true && $.browser.msie){
$(elc).width($(elc).width());
}
例如以下
if(cm[i].edittype === "select" && typeof(cm[i].editoptions)!=="undefined" &&
cm[i].editoptions.multiple===true &&
typeof(cm[i].editoptions.dataUrl)==="undefined" && $.browser.msie) {
$(elc).width($(elc).width());
}
此更改将阻止在请求加载之前width
设置非常小的选择。可能应该对将加载数据的相应调用的成功事件处理程序的内部进行相同的修复。我在 IE9 中测试了我的演示,不需要对 IE9 进行修复。$.ajax
dataUrl
width
$.ajax
grid.common.js
dataUrl
您可以在此处查看带有固定 jqGrid 代码的演示:单选演示、多选演示。您应该考虑到,服务器上没有将在editurl
. 尽管如此,您会在 Firebug 的 Fiddler 中看到将发送到服务器的已发布数据确实包含有关所选项目的信息。如果您想让演示在本地工作,您应该将其修改editurl
为 'clientArray' 并可能另外设置loadonce:true
。