2010-08-11 122 views
2

我在我的MVC項目中使用JqGrid-subGrid選項來獲得嵌套的gridview外觀。 我能夠在父網格中填充數據,我已經啓用了子網格,並給出了子網格Url來顯示innergrid數據。現在問題是,當網頁執行時,子網格不顯示,不僅如此,subGridUrl:方法沒有被調用。任何人都可以幫我弄清楚它背後的原因嗎?下面是我的代碼:JqGrid - SubGrid沒有顯示

jQuery的(文件)。就緒(函數(){

 jQuery("#list").jqGrid({ 

     url: '/jqgrid/DynamicGridData/', 

     datatype: 'json', 

     mtype: 'GET', 

     colNames: ['SurveyQnGrpId', 'SurveyQnGroup1'], 

     colModel: [ 
       { name: 'SurveyQnGrpId', index: 'SurveyQnGrpId', width: 40, align: 'left' }, 

       { name: 'SurveyQnGroup1', index: 'SurveyQnGroup1', width: 400, align: 'left'}], 

      pager: jQuery('#pager'), 

     rowNum: 10, 

     rowList: [5, 10, 20, 50], 

     sortname: 'SurveyQnGrpId', 

     sortorder: "SurveyQnGroup1", 

     viewrecords: true, 

     caption: 'My first grid', 

      subGrid: true, 

      subGridUrl: '/jqgrid/InnerGridData/', 

     subGridModel: [ 
      { 

       name: ['SurveyQnGrpId','SurveyQnId', 'SurveyQn', 'SurveyQnCategory', 'MandatoryQn','RadioOption3'], 

       width: [10,10, 100, 10, 10,10], 

       align: ['left', 'left', 'left', 'left'], 

       params: ['SurveyQnGrpId'] 

      }] 

    }); 
}); 

由於提前, Ancy

回答

2

你需要添加

subGrid: true, 
     jsonReader : { 
      root: "rows", 
      page: "page", 
      total: "total", 
      records: "records", 
      repeatitems: true, 
      cell: "cell", 
      id: "id", 
      subgrid: { 
       root: "rows", 
       repeatitems: true, 
       cell: "cell", 
       id: "id" 
      } 
     }, 

和你還需要下載新的jqgrid SRC目錄並選擇所有組件,因爲我認爲存在依賴關係

4

我發現它更容易傾倒內置子網格和使用他們的「次網格的網格」例如在飛行將一個全新的網格:

From their wiki:

subGrid: true, 
subGridRowExpanded: function(subgrid_id, row_id) { 
// we pass two parameters 
// subgrid_id is a id of the div tag created within a table 
// the row_id is the id of the row 
// If we want to pass additional parameters to the url we can use 
// the method getRowData(row_id) - which returns associative array in type name-value 
// here we can easy construct the following 
    var subgrid_table_id; 
    subgrid_table_id = subgrid_id+"_t"; 
    jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>"); 
    jQuery("#"+subgrid_table_id).jqGrid({ 
     url:"subgrid.php?q=2&id="+row_id, 
     datatype: "xml", 
     colNames: ['No','Item','Qty','Unit','Total'], 
     colModel: [ 
     {name:"num",index:"num",width:80,key:true}, 
     {name:"item",index:"item",width:130}, 
     {name:"qty",index:"qty",width:80,align:"right"}, 
     {name:"unit",index:"unit",width:80,align:"right"},   
     {name:"total",index:"total",width:100,align:"right",sortable:false} 
     ], 
     height: 100%, 
     rowNum:20, 
     sortname: 'num', 
     sortorder: "asc" 
    }); 
+0

很好的提示。甚至沒有看到那個。這種方式也允許更多的可定製性。 +1 – helios456 2012-04-19 15:48:05