for each loop

Hi,

I am trying to loop thru all rows in grid and based on a checkbox in one of the cells, turn the row background color green. I have it working when some checks the box but I want it to work dynamically for boxes already checked. For some reason my forEachRow is returning 0. I am placing it after my mygrid.loadXML() method but its doesn’t see the rows. How is the best way to do this?

mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
mygrid.setHeader('Name, Addres,Town,Phone,Cell Phone,Contact Pref,Email,Grant Site     
                             Usage,User Name,Password');
mygrid.setInitWidths("140,153,100,100,117,140,140,100,120,100");
mygrid.setColAlign("left,left, left,center,right,center,right,center,right,center,right");
mygrid.setColTypes("ed,ed,ed,ed,ed,coro,ed,ch,ro,ed,ed");		mygrid.setColSorting("db_connector,connector,connector,connector,connector,
                                  connector,connector,connector");
mygrid.setSkin("dhx_web");
			mygrid.attachHeader('#connector_text_filter,#connector_text_filter,#connector_text_filter,<button  id="delete_row">Delete Client</button>,<button id="add_user" >Add Client</button>');

mygrid.attachEvent("onEditCell", doOnCellEdit);
mygrid.attachEvent("onRowSelect",doOnRowSelected);
mygrid.attachEvent("onCheck", function(rId,cInd,state){
				if(state)
					mygrid.setRowColor(rId,"#00FF7F");
				else
					mygrid.setRowColor(rId,"#fff");
			});
			
mygrid.init(); 
mygrid.loadXML('db_connector.php');
			
mygrid.forEachRow(function(id){   <-- NOT WORKING ???????
				if ( mygrid.cellById(id,7).getValue() =="1") {
					var row_ID = mygrid.getRowId(id);
					 mygrid.setRowColor(row_ID, "#00FF7F");
				}
				
  });
			
  			var dp = new dataProcessor('db_connector.php');
			dp.init(mygrid);
			
			 
});
		

Loading is async, which means that next line after loadXML is executed while data is not loaded yet, it just in loading process.

You need to move that code to the callback of load command, like next

mygrid.loadXML('db_connector.php', function(){
    mygrid.forEachRow(function(id){
        ...            
    });
});

Stanislav,

Thanks that works great… :stuck_out_tongue: