Adding grand total to jqgrid programatically
I'm learning how to use jQGrid and i'm trying to put the grand total at bottom of grid but I can't it just appears as a blank row.
Im trying to show the 'Report' column grand total, there is my code:
function FillReportsGrid(GridName, PagerName) {
jQuery(GridName).GridUnload();
$.ajax({
url: '../ajaxwebservices/json.asmx/SearchMobileReport',
dataType:'json',
type:'POST',
contentType: 'application/json; charset=utf-8',
data: '{EmployeeID:\"' + $('#txtEmployeeID').val() + '\",Plant:\"' + $('#drplstPlant').val() + '\",Department:\"' + $('#开发者_运维技巧drplstDepartment').val() + '\",VendorName:\"' + $('#drplstVendorName').val() + '\",MobileNumber:\"' + $('#txtMobileNumber').val() + '\",InvoiceNumber:\"' + $('#txtInvoiceNumber').val() + '\",OrderBy:\"'+$('#ddlOrderBy').val()+'\",Month:\"'+$('#ddlMonth').val()+'\",Year:\"'+$('#ddlYear').val()+'\"}',
success: function(msg) {
var mydata = jQuery.parseJSON(msg);
jQuery(GridName).jqGrid({
datatype: "local",
data: mydata,
colNames: ['Bill #', 'MISC', 'Mobile #', 'Reporting', 'Invoice', 'Minutes', 'Comments', 'Cell Adj.', 'Data Adj.', 'Equip Adj.', 'Vendor Activity'],
colModel:
[{ name: 'BillID', index: 'BillID', width: 20, sorttype: 'int', key: true },
{ name: 'MISC', index: 'MISC', width: 40 },
{ name: 'MobileNumber', index: 'MobileNumber', width: 40},
{ name: 'VendorName', index: 'VendorName', width: 40},
{ name: 'Reporting', index: 'Reporting', width: 40, align: 'right', summaryType: 'sum', sorttype: 'number', formatter: 'number', summaryTpl: '<b>{0}</b>' },
{ name: 'Invoice', index: 'Invoice', width: 40, align: 'right' },
{ name: 'Minutes', index: 'Minutes', width: 40},
{ name: 'Comments', index: 'Comments', width: 40},
{ name: 'CellAdjustment', index: 'CellAdjustment', width: 40, align: 'right' },
{ name: 'DataAdjustment', index: 'DataAdjustment', width: 40, align: 'right'},
{ name: 'EquipAdjustment', index: 'EquipAdjustment', width: 40, align: 'right'},
{ name: 'VendorActivity', index: 'VendorActivity', width: 40}
],
pager: jQuery(PagerName),
rowNum: 25,
rowList: [10, 25, 50],
sortname: 'BillID',
sortorder: 'desc',
viewrecords: true,
caption: '',
autowidth: true,
ignoreCase: true,
height: "100%",
footerrow: true,
userDataOnFooter: true,
grouping: true,
groupingView : {
groupField: ['VendorName'],
groupColumnShow : [false],
groupText: ['<b>{0} - {1} Item(s)</b>'],
groupSummary : [true]
}
})
jQuery(GridName).jqGrid('navGrid', PagerName, { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Reload' });
jQuery(GridName).jqGrid('navButtonAdd', PagerName, { caption: "Add", title: "Add New User", buttonicon: 'ui-icon ui-icon-plus',
onClickButton: function() {
OpenAddNewItem();
}
});
}
});
}
Thank you, I hope someone can help me, and sorry if my english is not very good.
Add the loadComplete event and use the getCol method to calculate the sum:
loadComplete: function () {
var reportSum = jQuery(GridName).jqGrid('getCol', 'Reporting', false, 'sum');
jQuery(GridName).jqGrid('footerData', 'set',
{
BillID: 'Total:',
Reporting: reportSum
});
}
At the end I needed to add the loadComplete event and use the getCol method to calculate the sum at the bottom
精彩评论