Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Apr 01, 2008 15:20
open dhtmlx forum
I have used the api function and works as expected:    mygrid.setColumnHidden(idx,true);I have paginal ...

I have used the api function and works as expected:
    mygrid.setColumnHidden(idx,true);

I have paginal output that interrogates the hidden column on every page. I have therefore implemented the following callback on a page change:

        mygrid.setOnPageChanged(function(pageNo){
            mygrid.forEachRow(function(id){
                cellValue = mygrid.cells(id,10).getValue();
                   if (cellValue == "someValue"){
                       mygrid.setRowColor(id,"#FFAFBA");
                   }    
            });        
          });        

The forEachRow function always starts at the first row of the first page. In other words when on page 1 it loops through the rows on page 1. When on page 2 it loops through the rows on page 1 and 2. When on page 3 it loops through pages 1,2 and 3 etc. This seems inefficient for my purposes. Is there a way to interrogate only the rows of the page that the client is on? Somehow passing in a start and end row identifier?

Thanks
George
Answer posted by Support on Apr 02, 2008 00:20

Classic iterator

for (var i=0; i<grid.getRowsCount(); i++){
      // here i - index of row in grid
     do_something_with_row(index);
}
This way of iteration has the following characteristics:
  1. Used parameter - index (not ID), zero based position of a row in the grid;
  2. The order of iteration equals the order of elements in the grid;
  3. In case of paging mode - only current page is iterated;
  4. In case of tree grid - only currently visible rows are iterated;
  5. In case of smart rendering mode - not usable;
  6. In case of applied filtering - only rows that accept filtering rules will be included in iteration.

Built-in iterator

grid.forEachRow(function(id){
    // here id - row ID
     do_something_with_row(id);
})
This way of iteration has the following characteristics:
  1. Used parameter - row ID;
  2. Order of iteration is not equal to the current rows order in grid (basically it is equal to the adding order of rows to the grid, but it can be inconsistent);
  3. In case of paging or smart rendering mode - all rows parsed at the current moment will be affected;
  4. In case of tree grid - all rows will be processed, including those in closed branches;
  5. In case of applied filtering - all rows in the grid (including filtered out ones) will be included in iteration.
 

So you can use
for (var i=0; i<grid.rowsCol.length; i++){
     do_something_with_row(index);
}