Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery jqGrid动态选择选项_Jquery_Dynamic_Jquery Plugins_Jqgrid - Fatal编程技术网

Jquery jqGrid动态选择选项

Jquery jqGrid动态选择选项,jquery,dynamic,jquery-plugins,jqgrid,Jquery,Dynamic,Jquery Plugins,Jqgrid,我正在创建一个带有下拉列的jqgrid,并使用单元格编辑。我需要动态更改下拉列的选项,我已尝试通过将该列设置为: { name: "AccountLookup", index: "AccountLookup", width: 90, editable: true, resizable: true, edittype: "select", formatter: "select" }, 在beforeCellEdit事件中,我有: beforeEditCell: function(id, name

我正在创建一个带有下拉列的jqgrid,并使用单元格编辑。我需要动态更改下拉列的选项,我已尝试通过将该列设置为:

{ name: "AccountLookup", index: "AccountLookup", width: 90, editable: true, resizable: true, edittype: "select", formatter: "select" },
在beforeCellEdit事件中,我有:

beforeEditCell: function(id, name, val, iRow, iCol) {
        if(name=='AccountLookup') {             
            var listdata = GetLookupValues(id, name);
            if (listdata == null) listdata = "1:1";                              
            jQuery("#grid").setColProp(name, { editoptions: { value: listdata.toString()} })                                
        }
    },
GetLookupValues只返回格式为“1:1;2:2”等的字符串。 这很好,但是选项会在单击后填充-即我单击第1行中的AccountID,下拉列表为空,但是当我单击第3行中的AccountID时,我在第1行单击中设置的选项会显示在第3行单击中。等等因此,总是一个点击后面

有没有其他方法来实现我的需求?事实上,显示的下拉选项总是在变化,我需要在用户进入单元格进行编辑时加载它们。 也许我可以在beforeEditCell事件中找到select控件并手动输入其值,而不是使用setColProp调用?如果是这样的话,我能举一个这样做的例子吗


另一件事-如果下拉列表为空,并且用户没有取消单元格编辑,网格脚本将抛出一个错误。我正在使用clientarray编辑,如果这有什么不同的话。

您可以使用dataInit选项,如下所示:

{ name: "AccountLookup", index: "AccountLookup", width: 90,
    editable: true, resizable: true, edittype: "select", formatter: "select",
    editoptions: { dataInit: function( elem )
    {
        $(elem).empty()
            .append("<option value='1'>Apples</option>")
            .append("<option value='2'>Oranges</option>");
    } } }
{名称:“AccountLookup”,索引:“AccountLookup”,宽度:90,
可编辑:真,可调整大小:真,编辑类型:“选择”,格式化程序:“选择”,
editoptions:{dataInit:function(elem)
{
$(elem).empty()
.append(“苹果”)
.附加(“橙子”);
} } }

只需用GetLookupValues()函数替换静态Apple&Oranges选项。

还有一件事——选择列上的getChangedCells选项总是返回文本而不是值/Id——有办法解决这个问题吗?