Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Vanamali on Jan 28, 2010 04:02
open dhtmlx forum
Break from grid.forEachRow conditionally

I have grid with pagination. If I have each page with 10 rows and total number of rows in the grid is 31. I want to iterate thru each one of the row and get the id of the row which has the hiddenObjValue as Dummy in the UserData. If it is found, I want to break from the loop. Please find the below snippet. This is not working.

I have also tried making the loop manually iterating thru each record till grid.getRowsNum(). This throws a javascript error, when it tries to check the data for 11th rows which is not visible on the grid as it goes to the next page.

var id=0;
grid.forEachRow(function(rowIndex){
   if(workFilesGrid.getUserData(rowIndex,'hiddenObjValue') == 'Dummy') {         
     id = rowIndex;
     break;
  }
});

Answer posted by Alex (support) on Jan 29, 2010 02:30

Its not possible, you need to iterate by index, to be able to break from the loop

var id=0;

for (var i=0; i<grid.getRowsNum(); i++){
      if(grid.getUserData(grid.getRowId(i),'hiddenObjValue') == 'Dummy') {  
             id = grid.getRowId(i);
             break;
      }
}