Multiple Col Footer Summary

QuestionsMultiple Col Footer Summary
Gary Brett asked 9 years ago

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

12 Answers
Gary Brett answered 9 years ago

Sorry code currently using to display 'Total' column is grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2)}, false);

Thanks

Abu Ghufran answered 9 years ago

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.

Gary Brett answered 9 years ago

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

Abu Ghufran answered 9 years ago

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.

Gary Brett answered 9 years ago

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

Gary Brett answered 9 years ago

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?

Abu Ghufran answered 9 years ago

Here you are summing id column.

c = grid.jqGrid('getCol', 'id', false, 'sum');

Change 'id' with your desired column to sum.

Gary Brett answered 9 years ago

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);
};

Abu Ghufran answered 9 years ago

// get sum first
p = grid.jqGrid('getCol', 'payment_type', false, 'sum');

// get subtracted from var c
p = p – c;

// then use in footerData

Gary Brett answered 9 years ago

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);
};

Abu Ghufran answered 9 years ago

p = c- sum;
grid.jqGrid('footerData','set', {total: '£ '+sum.toFixed(2), received: '£ '+c.toFixed(2), premium_loan: '£ '+p.toFixed(2)}, false);

Abu Ghufran answered 9 years ago

These are general javascript issues, and out of the scope of phpgrid support.
I would recommend contacting some local technical staff.

If having issues in using phpgrid api, let me know.

Your Answer

12 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?