douxie9347 2011-04-24 07:50
浏览 122
已采纳

jqGrid中的Dependent ComboBox

I am using jqGrid and PHP.

I have two combo Boxes in my jqGrid. I want to change the second combo Box Value when I select a value from the first one while I am adding a new row or Editing a previous one using Form in my jqGrid.

Is it possible in jqGrid. Please help me with a working example.

  • 写回答

2条回答 默认 最新

  • douque9815 2011-04-25 04:17
    关注

    I am assuming that your both combo boxes uses database for their data.

    In the first combobox's editoptions please use the following code:

    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);
                    }
                 }
           });
         }
      }] 
    }   
    

    Now in your Add and Edit Options of your Grid use the following:

    recreateForm:true   
    

    Your controller should return data in the following syntax:

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

    As much as you need.

    Hope it will be helpful for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献