2009-04-21 56 views

回答

3

我無法確定如何實際將數據添加到jqGrid的子網格,但我能夠將數據添加到另一個網格中的網格。

我的主表格的樣子:

$("#" + tblNm).jqGrid({ 
       datatype: "local", 
       colNames: ['id', 'Last Name', 'First Name', 'Address'], 
       colModel: [{ 
        name: 'id', 
        index: 'id', 
        width: 75, 
        sortable: false 
       }, { 
        name: 'lastNm', 
        index: 'lastNm', 
        width: 90, 
        sortable: false 
       }, { 
        name: 'firstNm', 
        index: 'firstNm', 
        width: 100, 
        sortable: false 
       }, { 
        name: 'address', 
        index: 'address', 
        width: 200, 
        align: "left", 
        sortable: false 
       }], 
       width: "100%", 
       height: "100%", 
       caption: "Clients", 
       jsonReader: { 
        root: "clients", 
        page: "currpage", 
        total: "totalpages", 
        records: "totalrecords", 
        repeatitems: false, 
        id: "id" 
       }, 
       subGrid: true, 
       subGridRowExpanded: function(subgrid_id, row_id){ 
        console.debug("SubGrid_ID: " + subgrid_id + 
        " /row_id: " + 
        row_id); 
        var subgrid_table_id, pager_id; 
        subgrid_table_id = "mySubGridName" + row_id; 
        pager_id = "p_" + subgrid_table_id; 
        $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'></table>"); 
        jQuery("#" + subgrid_table_id).jqGrid({ 
         datatype: "local", 
         colNames: ['Order Id', 'Item Name', 'Cost'], 
         colModel: [{ 
          name: "ordId", 
          index: "ordId", 
          width: 20, 
          key: true 
         }, { 
          name: "itemName", 
          index: "itemName", 
          width: 130 
         }, { 
          name: "cost", 
          index: "cost", 
          width: 200, 
          align: "left" 
         }], 
         rowNum: 20, 
         caption: "Orders", 
         height: '100%', 
         width: '100%', 
         jsonReader: { 
          root: "orders", 
          page: "currpage", 
          total: "totalpages", 
          records: "totalrecords", 
          repeatitems: false, 
          id: "num" 
         } 
        }); 
       } 
      }); 

我做類似加載主電網:

$("#" + tblNm)[0].addJSONData(wrapper); 

然後,當我得到的亞格數據我做這樣的事情:

// click on the subgrid so that the table is added to the DOM 
// I think there are better ways of doing this... you'll want to look @ the jqGrid documentation 
$("#" + masterTblId + " tr[id='1'] td[role='grid'] a span").click(); 
// add the data to the subgrid 
$("#" + subGridId)[0].addJSONData(wrapper); 

最重要的部分是在jqGrid的subgridexpanded屬性中定義代碼,然後將bei ng能夠強制顯示子網格。

這種方法唯一的問題是,如果用戶點擊子網格區域,那麼它將被切換,當它們再次單擊它時,它不會正確顯示備份。我已要求社會對如何解決,在這裏:

Subgrid Caching or Stopping Subgrid data from being removed (jqGrid)

相關問題