请查看示例http://jsfiddle.net/6h1ok6g6/1/
var data = [
{shop:"shop1", day:"2015-11-1",document:"1", sell:"50",profit:"10",percent:"25"},
{shop:"shop1", day:"2015-11-1",document:"1", sell:"15",profit:"5",percent:"50"},
{shop:"shop1", day:"2015-11-2",document:"23", sell:"10",profit:"2",percent:"25"},
{shop:"shop1", day:"2015-11-2",document:"23", sell:"20",profit:"5",percent:"33"},
{shop:"shop1", day:"2015-11-3",document:"45", sell:"50",profit:"10",percent:"25"},
{shop:"shop1", day:"2015-11-3",document:"45", sell:"20",profit:"10",percent:"100"},
{shop:"shop2", day:"2015-11-1",document:"3", sell:"50",profit:"10",percent:"25"},
{shop:"shop2", day:"2015-11-1",document:"3", sell:"15",profit:"5",percent:"50"},
{shop:"shop2", day:"2015-11-2",document:"13", sell:"10",profit:"2",percent:"25"},
{shop:"shop2", day:"2015-11-2",document:"13", sell:"20",profit:"5",percent:"33"},
{shop:"shop2", day:"2015-11-3",document:"25", sell:"50",profit:"10",percent:"25"},
{shop:"shop2", day:"2015-11-3",document:"25", sell:"20",profit:"10",percent:"100"}
];
$("#grid").jqGrid({
datatype: "local",
data: data,
height: 'auto',
width: 'auto',
rowNum: 200000,
colModel: [
{ label: 'shop', name: 'shop', width:300 },
{ label: 'day', name: 'day'},
{ label: 'document', name: 'document'},
{ label: 'sell', name: 'sell', width: 90, sorttype:'number', formatter:"number", summaryType:'sum'},
{ label: 'profit', name: 'profit', width: 90, sorttype:'number', formatter:"number", summaryType:'sum'},
{ label: 'percent', name: 'percent', width: 90, sorttype:'number',formatter:"number" }
],
viewrecords: true, // show the current page, data rang and total records on the toolbar
caption: "test",
footerrow: true,
grouping:true,
groupingView : {
groupField : ['shop','day','document'],
groupColumnShow : [true,false,false],
groupSummary : [true,true,false],
groupText : ['<b>{0}</b>','<b>{0}</b>','<b>{0}</b>'],
groupCollapse : true,
groupOrder: ['asc','asc','asc'],
//showSummaryOnHide: false,
groupDataSorted : true,
groupSummaryPos: ['header','header','header']
}
});
有专栏&#34;百分比&#34;我可以通过公式计算:利润* 100 /(卖 - 赢) 我是为任何一行做的,但是如何对汇总行进行此操作?
平均摘要类型不正确答案;)
答案 0 :(得分:0)
找到溶剂here
{ label: 'percent', name: 'percent', width: 90,sorttype:'number',formatter:"number",
summaryType : function(value, name, record) {
// initialize the value object
if(typeof value === 'string'){
value = {totalAmount: 0, totalProfit: 0 };
}
// perform summary
if(record['sell']) {
value.totalAmount += parseFloat(record['sell']);
}
if(record['profit']) {
value.totalSebest += parseFloat(record['profit']);
}
return value;
},
formatter: function (cellval, opts, rwdat, act) {
// get the regional options and pass it to the custom formatter
opts = $.extend({}, $.jgrid.getRegional(this, 'formatter') , opts);
// determine if we are in summary row to put the value
if (opts.rowId === '') {
if(cellval.totalAmount > 0) {
var val = (cellval.totalAmount - cellval.totalProfit)/cellval.totalProfit*100;
return $.fn.fmatter('number', val, opts, rwdat, act)+'%';
} else {
return '0';
}
} else {
return $.fn.fmatter('number', cellval, opts, rwdat, act);
}
}