2011-04-18 53 views
0

我使用亞格爲jqGrid的。它是1級。以下是我的代碼。我不知道我在這裏做錯了什麼。但這種格式傳遞值次網格JSON格式_search,ND的rowNum

_search =假& ND = 1303143441927個&行= 20 &頁= 1 & SIDX = ID & SORD = ASC

代替

{ 「_search」:假, 「ND」:1303142903678, 「行」:100, 「頁」:1, 「SIDX」: 「」, 「SORD」: 「遞增」}

JSON格式。

$('#OrderGrd').jqGrid({ 
     url:'/AdvertiserCenter/CategoryLead.ashx?action=getOrderData&advertiserID=' + $('#advertiser_id').text() + '&startDate=' + $('input[id$="ViewFromCal_CalendarTbx"]').val() + '&endDate=' + $('input[id$="ViewToCal_CalendarTbx"]').val(), 
     datatype: 'json', 
     mtype: 'POST', 
     height:'100%', 
     width:'100%', 
     colNames: ['Order Number','Payment Type','Cost','Status','Total'], 
     colModel: [{ name: 'order_number', index: 'order_number',align:"center",width:'80px',sortable:false}, 
        { name: 'payment_type', index: 'payment_type',width:'110px',align:"left",sortable:false}, 
        { name: 'cost', index: 'cost',width:'200px',align:"right",sortable:false}, 


................. 

     subGrid: true, 
     subGridRowExpanded: function(subgrid_id, row_id) { 
       var subgrid_table_id, pager_id; 
       var rowdata = jQuery('#OrderGrd').getRowData(row_id); 
       var orderid = rowdata.order_number; 
       subgrid_table_id = subgrid_id+'_t'; 
       pager_id = 'p_'+subgrid_table_id; 
       $('#'+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 

       $.extend($.jgrid.defaults, 
       { datatype: 'jsonstring' }, 
       { ajaxGridOptions: { contentType: "application/json", 
       success: function (data, textStatus) { 
        if (textStatus == "success") { 
         var thegrid = $('#'+subgrid_table_id)[0]; 
         thegrid.addJSONData(data.data); 
         thegrid.grid.hDiv.loading = false; 
         switch (thegrid.p.loadui) { 
          case "disable": 
           break; 
          case "enable": 
           $("#load_" + thegrid.p.id).hide(); 
           break; 
          case "block": 
           $("#lui_" + thegrid.p.id).hide(); 
           $("#load_" + thegrid.p.id).hide(); 
           break; 
         } 
        } 
       } //end of success 
       }//end of ajaxGridOptions 
      });// end of extend 
       jQuery('#'+subgrid_table_id).jqGrid({ 
        url:'/AdvertiserCenter/CategoryLead.ashx?action=getOrderDetails&advertiserID=' + $('#advertiser_id').text() + '&orderID=' + orderid, 
        datatype:'json', 
        mtype: 'POST', 
        colNames: ['ID','Name','Company','Email','City','State/Province','Country','Cost'], 
        colModel: [{ name: 'id', index: 'id',align:'center',width:'80px',sortable:false}, 
         { name: 'name', index: 'name',width:'110px',align:'left',sortable:false}, 
         { name: 'company', index: 'company',width:'200px',align:'right',sortable:false}, 
         { name: 'email', index: 'email',width:'200px', align:'center',sortable:false}, 
         { name: 'city', index: 'city',align:'right',width:'205px',sortable:false}, 
         { name: 'state', index: 'state',width:'200px',align:'right',sortable:false}, 
         { name: 'country', index: 'country',width:'200px', align:'center',sortable:false}, 
         { name: 'cost', index: 'cost',align:'right',width:'205px',sortable:false}, 
         ], 
       rowNum:20, 
       pager: pager_id, 
       sortname: 'id', 
       sortorder: 'asc', 
       height: '100%' 
       }); 
       jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) 
      }, 
      subGridRowColapsed: function(subgrid_id, row_id) { 
       // this function is called before removing the data 
       //var subgrid_table_id; 
       //subgrid_table_id = subgrid_id+"_t"; 
       //jQuery("#"+subgrid_table_id).remove(); 
      }, 
     serializeGridData: function (data){ 
      return $.toJSON(data); 
     } 

感謝, 一個

回答

0

嘗試類似的東西:

serializeGridData: function (data){ 
    return 'json='+$.toJSON(data); 
    // or return {'json':$.toJSON(data)} 
} 

,你也可以登錄數據走出去,看看你是否已經達到給定事件

serializeGridData: function (data){ 
    var data = 'json='+$.toJSON(data); 
    console.log(data); 
    return data; 
} 

並btw確保有函數$ .toJSON(數據);因爲它不是一個標準的jQuery功能

0

感謝firegnom。我忘了爲子網格添加serializeGridData。

serializeGridData:功能(數據){ 返回$ .toJSON(數據);
}

它的偉大工程!

再次感謝。