最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - getting the sum using footerdata on jqgrid - Stack Overflow

programmeradmin4浏览0评论

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

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});
Share Improve this question edited Apr 23, 2013 at 0:42 StackOverflowUser asked Apr 22, 2013 at 8:53 StackOverflowUserStackOverflowUser 3033 gold badges8 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

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 pare with your non working demo. I hope you will find the error in your code.

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.

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 es from trying to sum a column that is as yet undefined.

发布评论

评论列表(0)

  1. 暂无评论