DHTMLX Docs & Samples Explorer

Index
dhtmlxgrid

## Attaching Statistics Counters to External Objects

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.