2011-09-20 129 views
0

我想使用json數據而不使用subgridurl(因爲這會調用頁面的每一行擴展)來彈出一個子網格。但得到錯誤:"t.rows is undefined"(在grid.base.js中)。代碼是如下: 版本的模塊用於:jqGrid SubGrid沒有填充

  1. 的jquery-1.6.2.js
  2. 的jqGrid 3.3.2

預先感謝。

 jQuery(gridID).jqGrid({ 
      url: dataURL, 
      datatype: "json", 
      colNames: ['ID', 'FirstName', 'LastName', 'Address1', 'Address2', 'City', 'Country'], 
      colModel: [ 
        { name: 'id', width: 200, sortable: false }, 
        { name: 'firstName', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} }, 
        { name: 'lastName', width: 200, sortable: false, hidden: true }, 
        { name: 'address1', width: 200, sortable: false, hidden: true }, 
        { name: 'address1', width: 200, sortable: false, hidden: true }, 
        { name: 'city', width: 200, sortable: false, hidden: false}, 
        { name: 'country', width: 200, sortable: false, hidden: false} 
       ], 
      rowNum: 10, 
      rowList: [10, 20, 30], 
      pager: '#pager2', 
      sortname: 'id', 
      viewrecords: true, 
      sortorder: "desc", 
      caption: "TEST", 
      height: "400px", 
      subGrid: true, 

      subGridRowExpanded: function(subgrid_id, row_id) { 
       subGridID = subgrid_id; 
       jQuery("#" + subGridID).html("<div style='margin-left:415px'><table id='" + subGridID + "' class='scroll'><tr><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td></tr></table></div>"); ; 
       jQuery("#" + subGridID).jqGrid(
     { 
      datatype: function(pdata) { getDataSubGrid(pdata); }, 
      colNames: ['ID', 'FirstName', 'LastName', 'Address1', 'Address2', 'City', 'Country'],, 
      colModel: [ 
        { name: 'id', width: 200, sortable: false }, 
        { name: 'firstName', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} }, 
        { name: 'lastName', width: 200, sortable: false, hidden: true }, 
        { name: 'address1', width: 200, sortable: false, hidden: true }, 
        { name: 'address1', width: 200, sortable: false, hidden: true }, 
        { name: 'city', width: 200, sortable: false, hidden: false}, 
        { name: 'country', width: 200, sortable: false, hidden: false} 
       ], 
      height: 100, 
      rowNum: 20, 

      sortorder: "asc", 
      height: '100%' 
     }); 
      } 

     }); 

     jQuery("#mygrid").jqGrid('#mygrid', '#pager2', { edit: false, add: false, del: false }); 
    } 


    function getDataSubGrid(pData) { 
     gridId = "#mygrid_t"; 
     $.ajax({ 
      type: 'GET', 
      contentType: "application/json; charset=utf-8", 
      url: myURL,//myurl would get json data from web service 
      data: '{}', 
      dataType: "json", 
      success: function(data, textStatus) { 


       ReceivedClientDataForSubGrid(getMain(data).rows); 
      }, 
      error: function(data, textStatus) { 
       alert('An error has occured retrieving data subgrid!'); 
      } 
     }); 
    } 


    function ReceivedClientDataForSubGrid(data) { 
     var thegrid = $("#" + subGridID); 
     if ($(thegrid).length == 0) alert('NOT EXISTS'); 

     thegrid.clearGridData(); 
     alert(data.length);//this shows 10 
     for (var i = 0; i < data.length; i++) { 
     thegrid.addRowData(i + 1, data[i]); 
     } 
    } 


    function getMain(dObj) { 
     if (dObj.hasOwnProperty('d')) 
      return dObj.d; 
     else 
      return dObj; 
    } 

回答

0

錯誤「t.rows is undefined」意味着您通常使用錯誤的HTML片段作爲網格。例如,如果您使用<div>而不是<table>,則會出現此錯誤。

此外,我強烈建議您升級到當前的jqGrid版本4.1.2。今天jqGrid 3.3.2的使用,特別是jQuery相對較新的1.6.2版本的使用可以解決問題。這就像試圖在新的汽車中使用30年前的汽油一樣。您可能會收到嚴重問題。