使用jqGrid,无论如何在编辑记录弹出窗口中都有动态下拉列表吗?

时间:2012-08-27 16:23:29

标签: jquery jqgrid

我有一个包含三个字段的记录,它们都是下拉列表。如果它们是独立的记录,它一切正常但我想在那里如果你改变第一个下​​拉列表,那么第二个下拉列表中的项目列表会发生变化吗?这在jqgrid中是否可行。

我的代码的简化版本现在看起来像这样:

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"} }

    ],

1 个答案:

答案 0 :(得分:2)

在jqGrid中实现依赖选择没有简单的方法。不过,我在the demo the answer中显示了如何实现依赖选择。我在树案例中演示了实现:内联编辑,表单编辑和搜索工具栏。

在您的情况下,您使用dataUrl editoptions代替参考演示中使用的value。然而,实施可以基于相同的想法。您可以为“main”选择注册change事件,并向服务器发出$.ajax请求,以获取相关选择的select选项的子集。在success的{​​{1}}句柄内,你可以像我的演示一样做同样的事情。