I'm using subgrid for jqgrid. It's 1 level. Following is my code.I don't know what I'm doing wrong here. But it passes values in this format
_search=false&nd=1303143441927&rows=20&page=1&sidx=id&sord=asc
instead of
{"_search":false,"nd":1303142903678,"rows":100,"page":1,"sidx":"","sord":"asc"}
json format.
$('#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 = sub开发者_如何学Cgrid_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);
}
Thanks, A
try something like that :
serializeGridData: function (data){
return 'json='+$.toJSON(data);
// or return {'json':$.toJSON(data)}
}
and also you can log data going out to see if you are reaching given event
serializeGridData: function (data){
var data = 'json='+$.toJSON(data);
console.log(data);
return data;
}
and btw make sure that there is function $.toJSON(data); as it is not a standard jquery function
Thanks firegnom. I forgot add serializeGridData for a subgrid.
serializeGridData: function (data){
return $.toJSON(data);
}
It works great !
Thanks again.
精彩评论