Reputation: 303
I have a column name Total.
And I'm also using the footer
value of the jqgrid.
Example this is the column
Total
100
-98
-76
98
76
how can I get the sum of the row
using the footer data.
here is my code.
note: if i use 'sum' it gives me 'NaN'
value.
var parseTotal= grid.jqGrid('getCol', 'Total', false, 'sum');
grid.jqGrid('footerData', 'set', { Total: parseTotal});
Upvotes: 3
Views: 20907
Reputation: 151
Not a jqGrid expert by any means, but shouldn't the column referenced in the 'getCol' method be the column you want to sum -- 'amount' -- instead of the column into which you want to put the sum -- 'Total'? The Nan comes from trying to sum a column that is as yet undefined.
Upvotes: 0
Reputation: 221997
You should post more full code which reproduce the problem. I tried some options: the input data as string, the data as integers, using formatter: "integer"
, using no formatters and so on.
I found no input data of no column definition which produce the described results. Look at the demo
which works and compare with your non working demo. I hope you will find the error in your code.
Upvotes: 10
Reputation: 3082
I am assuming that you put the above code in gridComplete function like this:
gridComplete: function(){
var parseTotal= $(this).jqGrid('getCol', 'Total', false, 'sum');
$(this).jqGrid('footerData', 'set', { Total: parseTotal});
}
Now, the issue of returning NaN occurs when one of the cells in the column contain a null value(white space). So , to convert white spaces to value 0, use number
formatter in the colmodel for column total
:
ie;
colModel:[
...............
{name:"Total",index:"Total", formatter: 'number'},
......
],
Also ensure that the column index is correctly spelled.
Upvotes: 2