Hi Abu, is it possible to have more than 1 columns summarised in footer? I have my grid showing only 1 sum on a column called 'Total' which is great but I also have another column called 'Received' that would be good to sum also?
I tried editing the footer example but didn't really know where to start!
Thanks
Sorry code currently using to display 'Total' column is grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2)}, false);
Thanks
You can show other footer data under some 'received' column by changing :
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+sum2.toFixed(2)}, false);
You will need to set sum2 and rename 'received' with exact column name.
Thank you Abu, I had tried that last night but the grid hangs on 'Loading', my exact column names are 'total' & 'received' and my script looked like this;
function grid_onload()
{
var grid = $("#list2");
// sum of displayed result
sum = grid.jqGrid('getCol', 'total', false, 'sum'); // 'sum, 'avg', 'count' (use count-1 as it count footer row).
// record count
c = grid.jqGrid('getCol', 'id', false, 'sum');
// LINE BELOW WORKS GREAT
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2)}, false);
// THIS MAKES GRID STICK ON LOADING
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+sum2.toFixed(2)}, false);
};
I remember having similar issues when removing the running totals but cant recall how it fixed?
I will keep trying but any ideas?
Gary
First, you should use footerData once.
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+c.toFixed(2)}, false);
And in your code, sum2 is not defined. Try renaming it to 'c' or appropriate var.
Check f12 (debug console) for exact js error.
Thanks Abu, that has stopped the loading error now. What is the +c doing can you tell, it seems to sum up random numbers for example;
[received col] [sum+c]
100 18
200 19
400 41
Can work out what this is summing up
Hi Abu, I think what its doing is adding up the ID number of the record, for example if there are 2 records in the grid with ID of 23, 24 it outputs 47 rather than summing the received column?
Is there a way I can tell it to sum the received column rather than count ID?
Here you are summing id column.
c = grid.jqGrid('getCol', 'id', false, 'sum');
Change 'id' with your desired column to sum.
Fantastic Abu, I couldn't see it for looking but many thanks it works a treat!.
Not important, just curious, as a test I tried to see if I could perform a calculation in footer to subtract total from received using code below? I added the p value to achieve this but it stays on loading, is this even possible in a footer before I spend lost of time trying?
// e.g. to show footer summary
function grid_onload()
{
var grid = $("#list2");
// sum of total
sum = grid.jqGrid('getCol', 'total', false, 'sum'); // 'sum, 'avg', 'count' (use count-1 as it count footer row).
// sum of received amount
c = grid.jqGrid('getCol', 'received', false, 'sum');
// sum of received amount
p = grid.jqGrid('getCol', 'payment_type', false, '+sum – +c');
// 4th arg value of false will disable the using of formatter
//grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2)}, false);
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+c.toFixed(2), payment_type: '£ '+p.toFixed(2)}, false);
};
// get sum first
p = grid.jqGrid('getCol', 'payment_type', false, 'sum');
// get subtracted from var c
p = p – c;
// then use in footerData
Hi Abu, appreciate your patience on this, adding it to footer wipes out all summaries, F12 doesn't show any issues?
function grid_onload()
{
var grid = $("#list2");
// sum of total
sum = grid.jqGrid('getCol', 'total', false, 'sum');
// sum of received amount
c = grid.jqGrid('getCol', 'received', false, 'sum');
// sum of total – received
p = grid.jqGrid('getCol', 'premium_loan', false, 'sum');
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+c.toFixed(2), premium_loan: '£ 'p = c- sum;.toFixed(2)}, false);
};
p = c- sum;
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+c.toFixed(2), premium_loan: '£ '+p.toFixed(2)}, false);