Custom footer calculation

QuestionsCustom footer calculation
Hamish asked 8 years ago

Hi All,

Is there a way to use a custom function to calculate a value for the footer?

i.e. at the moment I am using this snippet from the documentation page:

function grid_onload()
{
var grid = $("#list1");

// sum of displayed result
avg= grid.jqGrid('getCol', 'total', false, 'avg');

//SOME CODE REMOVED.

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

grid.jqGrid('footerData','set', {id: 'Total: ' + sum, invdate: 'Sub Total: '+sum_running, total: 'Grand Total: '+sum_table});
};

I'd like to be able to use a custom function, specifically I need to calculate an average excluding "0" values. I have to be able to calculate at runtime as the grid is filtered by the user.

thanks,

Hamish

2 Answers
Abu Ghufran answered 8 years ago

Hi,

You can use JS functions of grid to iterate thru all rows and calculate non-zero average.
Refer this code:
http://pastebin.com/EVWMwBc7

amount: field
list1: grid id
id: column to add footer

Hamish answered 8 years ago

Hi Abu,

Thank you very much for your help.

I managed to use that snippet and get what I needed.

Thanks,

Hamish

Your Answer

17 + 5 =

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?