getting the sum using footerdata on jqgrid

非 Y 不嫁゛ 提交于 2019-11-27 03:41:12

问题


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

回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/16142993/getting-the-sum-using-footerdata-on-jqgrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!