getting the sum using footerdata on jqgrid

末鹿安然 提交于 2019-11-28 10:37:08

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.

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

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