jqGrid动态选择选项 [英] jqGrid dynamic select option
问题描述
{name:AccountLookup,index:AccountLookup,width:90,editable:true,resizable:true,edittype:select,formatter:select},
/ pre>
然后在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事件中的选择控件,并手动输入其值而不是使用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>);
}}}
只需更换静态苹果&您的GetLookupValues()函数使用Oranges选项。
I'm creating a jqgrid with drop down columns and I'm using cell editing. I need the options of the drop down columns to change dynamically and I've tried implementing this by setting the column to be:
{ name: "AccountLookup", index: "AccountLookup", width: 90, editable: true, resizable: true, edittype: "select", formatter: "select" },
and then in the beforeCellEdit event I have:
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 just returns a string in the format "1:One;2:Two" etc. That works fine however the options are populated one click behind - ie i click on AccountID in row 1, and the dropdown is empty, however when I then click on AccountID in row 3 the options I set in the row 1 click are shown in the row 3 click. And so on. So always one click behind.
Is there another way of achieving what I need? Bacially the dropdown options displayed are always changing and I need to load them as user enters the cell for editing. Perhaps I can somehow get at the select control in the beforeEditCell event and manually enter its values instead of using the setColProp call? If so could I get an example of doing that please?
Another thing - if the dropdown is empty and a user doesn't cancel the cell edit, the grid script throws an error. I'm using clientarray editing if that makes a difference.
解决方案You could use the dataInit option, like this:
{ 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>"); } } }
Just replace the static Apples & Oranges options with your GetLookupValues() function.
这篇关于jqGrid动态选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!