Reputation: 374
I have a JqGrid whith a data footer where I'd like to put the sum of the column. I'd also like that that when the cell value equal zero in the grid, it will be color in grey. To do so I've creatted a custom formatter:
currencyFmatter = function (cellValue, options, rowObject) {
if (cellValue == 0)
return '<span class="cellWithoutBackground" style="color:#E1E1E1;">' +
$.fn.fmatter('number', cellValue, options, rowObject)
+ '</span>';
return $.fn.fmatter('number', cellValue, options, rowObject);
};
Which I call like this
{ name: 'Name', index: 'Name', align: 'center', width: '200px' },
{ name: 'January', index: 'Months["January"].Amount', align: 'center',
formatter:currencyFmatter}
The coloration is good but the sum in the data footer don't work anymore it always says 0.
loadComplete: function () {
var janSum = $('#jqgEndYear').jqGrid('getCol', 'January', false, 'sum');
var febSum = $('#jqgEndYear').jqGrid('getCol', 'February', false, 'sum');
var marSum = $('#jqgEndYear').jqGrid('getCol', 'March', false, 'sum');
var aprSum = $('#jqgEndYear').jqGrid('getCol', 'April', false, 'sum');
var maySum = $('#jqgEndYear').jqGrid('getCol', 'May', false, 'sum');
var junSum = $('#jqgEndYear').jqGrid('getCol', 'June', false, 'sum');
var julSum = $('#jqgEndYear').jqGrid('getCol', 'July', false, 'sum');
var augSum = $('#jqgEndYear').jqGrid('getCol', 'August', false, 'sum');
var sepSum = $('#jqgEndYear').jqGrid('getCol', 'September', false, 'sum');
var octSum = $('#jqgEndYear').jqGrid('getCol', 'October', false, 'sum');
var novSum = $('#jqgEndYear').jqGrid('getCol', 'November', false, 'sum');
var decSum = $('#jqgEndYear').jqGrid('getCol', 'December', false, 'sum');
$('#jqgEndYear').jqGrid('footerData', 'set', { Code: 'Total:',
January: janSum,
February: febSum,
March: marSum,
April: aprSum,
May: maySum,
June: junSum,
July: julSum,
August: augSum,
September: sepSum,
October: octSum,
November: novSum,
December: decSum
});
}
});
If you have any idea of why the sum won't calculate, I be pleased to read it. Thanks in advance for your help
Upvotes: 1
Views: 7546