2011-04-27 139 views
1

我正在使用jqgrid,我添加了一个包含字段的行:textbox和selectbox。jqgrid选择框选项集选择

通过从下拉列表中选择年龄来添加行后,当我点击此行进行编辑时,年龄下拉列表必须默认标记选定的值。如何实现这一目标?

这是示出了列数据的代码:

colModel:[       
{name:'user_id',index:'user_id', width:150,align:"center",editable:false,editoptions:{readonly:true,size:10}},  
{name:'user_name',index:'user_name', width:250, align:"left",editable:true,editoptions:{size:30}}, 
{name: 'Age', width: 40, editable: true, formatter: 'select', 
edittype: 'select', editoptions: { value: age_list }, 
hidden: true, editrules: { edithidden: true }} 
] 

其中“age_list”是年龄值的在一个JavaScript阵列的形式排列。

+1

jqGrid的真正自动标记在默认情况下将选择值我的所有测试都是内联或表单编辑。你应该发布更多的代码,因为问题在发布的代码之外是确定的。例如你使用哪个'age_list'?哪种格式包含“年龄”列?你如何填补网格? – Oleg 2011-04-27 18:28:15

回答

2

使用edittype: 'custom'为您列,然后你就可以创建自己的控件的HTML:在jqGrid的文档维基

<script> 
jQuery("#grid_id").jqGrid({ 
... 
    colModel: [ 
     ... 
     {name:'price', ..., editable:true, edittype:'custom', editoptions:{custom_element: functionThatReturnsHtmlElement, custom_value: functionThatReturnsTheValueYouNeed} }, 
     ... 
    ] 
... 
}); 
</script> 

更多细节:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editable

+0

我找不到像上面说的那样设置默认值的方法:** <选项...选择>显示 **。我尝试过:** editoptions:{value:age_list,defaultValue:“2”} **但这不起作用。我发现默认情况下,下拉菜单中的第一个选项已被选中。 – 2011-04-27 14:56:49

+0

我会编辑更清晰。你必须使用'custom'编辑类型,你还没有这样做。 – Milimetric 2011-04-27 14:58:44

+0

custom_element和custom_value表示什么? – 2011-04-27 15:14:37