使用jqGrid,在编辑记录弹出窗口中是否总有动态下拉菜单? [英] Using jqGrid, Is there anyway to have dynamic dropdown in the edit record popup?
问题描述
我有一个包含三个字段的记录,它们都是下拉列表.如果它们是独立记录,那么一切正常,但是我想在哪里更改第一个下拉列表,然后第二个下拉列表中的项目列表更改?在jqgrid中有可能吗?
I have a record that has three fields and they are all dropdowns. It all works fine if they are independent records but i would like it where if you change the first dropdown, then the list of items in the second dropdown changes? Is this possible in jqgrid.
我的代码的简化版本现在看起来像这样:
Simplified version of my code looks like this now:
jQuery("#marketDataGrid").jqGrid({
mtype: "POST",
url: "/Application/MarketData/" + id,
datatype: "json",
colNames: ["", "Id","Source", "API"],
colModel: [
{ name: "ApplicationId", index: "ApplicationId", hidden: true, width: 0, editable: true, editoptions: { readonly: true} },
{ name: "Id", index: "Id", hidden: false, width: 30, editable: false, editoptions: { readonly: true} },
{ name: "MarketDataSource", index: "MarketDataSource", editoptions: { dataUrl: "/MarketDataSource/GetSelectDataRequired" }, editrules: { required: true }, editable: true, edittype: "select", width: 155, stype: 'select', searchoptions: { sopt: ['eq', 'ne'], dataUrl: "/MarketDataSource/GetSelectData"} },
{ name: "API", index: "API", editoptions: { dataUrl: "/API/GetSelectDataRequired" }, editrules: { required: true }, editable: true, edittype: "select", width: 155, stype: 'select', searchoptions: { sopt: ['eq', 'ne'], dataUrl: "/API/GetSelectData"} }
],
推荐答案
在jqGrid中没有实现依赖选择的简单方法.不过,我在
There are no simple way to implement dependent selects in jqGrid. Nevertheless I shown in the demo from the answer how dependent selects could be implemented. I demonstrated the implementation in tree cases: inline editing, form editing and searching toolbar.
在您的情况下,请使用editoptions
的dataUrl
而不是引用的演示中使用的value
.然而,该实现可以基于相同的想法.您可以为主要"选择注册change
事件,并向服务器发出$.ajax
请求,以获取从属选择的选择选项的子集.在$.ajax
的success
手柄内部,您将能够执行与演示中相同的操作.
In your case you use dataUrl
of editoptions
instead of value
used in the referenced demo. Nevertheless the implementation can be based on the same idea. You can register change
event for the "main" select and make $.ajax
request to the server to get the subset of select's options of the dependent select. Inside of success
handle of $.ajax
you will be able to do the same thing like in my demo.
这篇关于使用jqGrid,在编辑记录弹出窗口中是否总有动态下拉菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!