3

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});
StackOverflowUser
  • 305
  • 3
  • 8
  • 19

3 Answers3

9

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

enter image description here

which works and compare with your non working demo. I hope you will find the error in your code.

Oleg
  • 220,925
  • 34
  • 403
  • 798
1

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.

Sharun
  • 3,022
  • 6
  • 30
  • 59
0

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.

jenisysJohn
  • 141
  • 1
  • 6