【问题标题】:Dependant ComboBox in jqGridjqGrid中的依赖组合框
【发布时间】:2011-04-24 07:50:11
【问题描述】:

我正在使用 jqGrid 和 PHP。

我的 jqGrid 中有两个组合框。当我在我的 jqGrid 中添加新行或使用 Form 编辑前一个行时从第一个中选择一个值时,我想更改第二个组合框值。

在 jqGrid 中可以吗?

【问题讨论】:

    标签: php jqgrid


    【解决方案1】:

    【讨论】:

    • 对我也有帮助。谢谢。
    【解决方案2】:

    我假设你的两个组合框都使用数据库来存储它们的数据。

    在第一个组合框的编辑选项中,请使用以下代码:

    editoptions: {
       value: "1:One;2:Two",
       dataEvents: [{
           type: "change",
           fn: function(e) {
              $("#your_grid").setColProp("second_combo", { 
                  editoptions: { value: "-1:--Select One--"} 
              });
              var v = parseInt($(e.target).val(), 10);
              $.ajax({
                 url: "path/to/your/controller/"+v,
                 dataType: "html",
                 success: function(data) {
                    if ($(e.target).is(".FormElement")) {
                    var form = $(e.target).closest("form.FormGrid");                                                       
                    $("select#second_combo.FormElement", form[0]).html(data);
                    }
                    else {
                       // inline editing
                       var row = $(e.target).closest("tr.jqgrow");
                       var rowId = row.attr("id");
                       $("select#" + rowId + "_second_combo", row[0]).html(data);
                    }
                 }
           });
         }
      }] 
    }   
    

    现在在您的网格的 AddEdit 选项中使用以下内容:

    recreateForm:true   
    

    您的控制器应以以下语法返回数据:

      <option value="val">Display</option>
    

    只要你需要。

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      相关资源
      最近更新 更多