Categories | Question details Back To List | ||
automatically calculated values Hi, i'm trying to use Custom statistics counter (automatically calculated values). I use the following code: mygrid._in_header_stat_sum2=function(tag,index,c){ var calck=function(){ var summ=0; for (var i=0; i < mygrid.getRowsNum(); i++){ summ+= parseFloat(mygrid.cells(i,index).getValue()); } return summ; } this._stat_in_header(tag,calck,index,c); But my output ist NaN. Do you know what's wrong with my code? Thanks in advance! Answer posted by Support on Sep 08, 2008 06:23 >>for (var i=0; i < mygrid.getRowsNum(); i++){ >>summ+= parseFloat(mygrid.cells(i,index).getValue()); The "i" is row index, but you are using its as parameter for cells command, which expects row ID as parameter This will work if you have row IDs as numbers from 0 to N , but not safe in common case ( there is a cells2 command , which works exactly the same but accept row index as first parameter ) >>But my output ist NaN. If you have at least one row with non-numeric value in calculated column - it will cause such result. You can change code as for (var i=0; i < mygrid.getRowsNum(); i++){ var value=parseFloat(mygrid.cells(i,index).getValue()); if (!isNaN(value)) summ+=value; } updated code will ignore any non-numeric cells |