Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by john on Apr 17, 2008 08:48
open dhtmlx forum
add in jsp row count, and a total

I will like to add the total of record, and the sum of prices of one column in the jsp page (not as part of the grid)... how I can?

This is my script code:
.....
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setHeader("id, name ,price,....................
mygrid.setColTypes( "ro,ro..................
mygrid.init();
mygrid.enablePagingWT(true,12,0,"recinfoArea");
mygrid.loadXML(loadDataURL);

This in my HTML code:
...............
Total records ????? Total Amount $ ???????
...............
<div align="center" id="gridbox" style="width:100% ; height:300px;" style="background-color:white ">     </div>
<div id="recinfoArea" style="width:100%;"></div>
<div align="center" id="msg_gridbox" class="messageGrid" >     </div>    
Answer posted by Support on Apr 17, 2008 09:34
While the main purpose of statistics counters is to show data inside the headers|footers of the grid, it is pretty easy to use them to fill some custom area on the page with the related data.

For example, if you have the following code:
grid._in_header_stat_count=function(tag,index,c){             //shortcut for statistics counter
    var calck=function(){                                               // define the function which will be used for calculations
        return this.getRowsNum();
    }
    this._stat_in_header(tag,calck,index,c);                    //call the default statistics handler processor
}
And somewhere on the page you have:
there are <span id="grid_count"></span> rows in my grid
You can link stat_count to the span element in the following way:
grid._in_header_stat_count(document.getElementById('grid_count'),1);
After such command the content of grid_count element will be always equal to the number of rows in the grid.
One cool detail should be noted here: if you add|delete the rows or reload the grid, the content of html tag will be correctly updated after each operation.

The same trick can be used with any "in header shortcut", but there is no much sense in it for the static ones.
Answer posted on Apr 17, 2008 09:52
i've changed my code but it cant get it to work, here is it:


This is my script code:
.....
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setHeader("id, name ,price,....................
mygrid.setColTypes( "ro,ro..................
mygrid.init();

mygrid._in_header_stat_count=function(tag,index,c){    var calck=function(){     return this.getRowsNum();    }    this._stat_in_header(tag,calck,index,c);              }
mygrid._in_header_stat_count(document.getElementById('grid_count'),1);

mygrid.enablePagingWT(true,12,0,"recinfoArea");
mygrid.loadXML(loadDataURL);

This in my HTML code:
...............
Total records <span id="grid_count"></span>
...............
<div align="center" id="gridbox" style="width:100% ; height:300px;" style="background-color:white ">     </div>
<div id="recinfoArea" style="width:100%;"></div>
<div align="center" id="msg_gridbox" class="messageGrid" >     </div>   
Answer posted by Support on Apr 18, 2008 07:52
Please check attached sample
Attachments (1)