用于搜索的子网格json格式,以及rowNum

时间:2011-04-18 16:25:35

标签: jqgrid

我正在为jqgrid使用subgrid。这是1级。以下是我的代码。我不知道我在这里做错了什么。但它以这种格式传递值

  

_search =假安培; ND = 1303143441927&安培;行数= 20安培;页= 1&安培; SIDX = ID&安培; SORD = ASC

而不是

  

{ “_搜索”:假, “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);   
        }

谢谢, 甲

2 个答案:

答案 0 :(得分: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(data);因为它不是标准的jquery函数

答案 1 :(得分:0)

感谢firegnom。我忘了为子网格添加serializeGridData。

serializeGridData:function(data){   返回$ .toJSON(数据);
}

效果很好!

再次感谢。