实现底部总计功能,设置属性: footerrow : true, userDataOnFooter : true,
jQuery("#list2")
.jqGrid(
{
url: 'initlist',
datatype: "json",
height: 140,
autowidth: true,
colNames: ['时间段', '车辆数', '收入'],
colModel: [
{
name: 'time',
index: 'time',
width:200,
align: 'center',
},
{name : 'carnum',width:100,align: 'center'},
{name : 'shouru',width:100,align: 'center'},
],
jsonReader: {
root: "dataRows",
page: "curPageNo",
total: "totalPages",
records: "totalRecords",
repeatitems: false,
id: "0"
},
sortname: 'time',
sortorder: 'asc',
mtype: "post",
viewrecords: true,
caption: "分析",
footerrow : true,
userDataOnFooter : true,
gridComplete: function () {
//合计
var rows = $("#list2").jqGrid("getRowData");
var carnum=0,shouru=0;
for(var i = 0, l = rows.length; i<l; i++) {
carnum += (rows[i].carnum - 0);
shouru += (rows[i].shouru - 0);
}
$("#list2").jqGrid("footerData", "set", {
time:"合计",
carnum:carnum,
shouru:shouru,
});
}
});
如果有很多字段,只想合计其中的某几个字段,只需要在gridComplete方法中,计算需要的字段即可。