Keep selected row after grid refresh

Is there an easy way to keep a row selected in a grid after the grid contents are refreshed? I am calling selectRow() on the grid after the refresh but it’s not working. (Interestingly, if I have an alert statement and click ‘ok’ before I call selectRow() it does work.)


selectRow() should be added after xml is completely loaded.


The 4th parameter of the updateFromXML method is function that is called after xml loading:


grid.updateFromXML(url,insert_mode,del_mode,function(){


grid.selectRow(…)


})


I am not using an update function but rather:



grid.clearAll();
grid.load(url, “xml”);
grid.selectRow(grid.getRowIndex(rowId), true, true, true);



This is not working unless I have an alert() statement.  Does the click of the alert execute some code that makes it work?
        


In this case the same approach can be used:


grid.clearAll();
grid.load(url,doAfterLoading,“xml”);


function doAfterLoading(){
grid.selectRow(grid.getRowIndex(rowId), true, true, true);


}




Why does



grid.clearAll();
grid.load(url, “xml”);
grid.selectRow(grid.getRowIndex(rowId), true, true, true);



not work?  Why do I have to do it within the load function?

Loading is async., load command just start loading process , so next command will be executed while data still in loading process.
When second parameter of load command used - code inside it will be executed exactly after data loading


I am doing what you suggested but it isn’t working.  I am getting the feeling that it is still executing before the grid is finished loading, because when I print out



grid.getRowIndex(row) in doAfterLoading() it is undefined.



The following is the code:



grid.clearAll();
grid.load(url, this.doAfterLoading(grid, row), “xml”);



this.doAfterLoading = function (grid, row) {



 alert(grid.getRowIndex(row));  //this prints ‘undefined’
 grid.selectRow(grid.getRowIndex(row), true, true, true);  
 
}



 


Not exactly …


Try to use the following:


grid.load(url, this.doAfterLoading, “xml”);


instead of


grid.load(url, this.doAfterLoading(grid, row), “xml”);

The function requires those parameters (grid, row) in order to execute properly?


The second parameter of the load method is on loading end event handler. It isn’t possible to pass custom parameters into it.


doAfterLoading(){





}


This still did not work:



grid.clearAll();
grid.load(url, this.doAfterLoading(), “xml”);        



this.doAfterLoading = function () {
 grid.selectRow(2, true, true, true);      
}


Well… once again… Please, be attentive


grid.load(url, this.doAfterLoading, “xml”);


there isn’t ().

Sorry, I posted that before I got your answer.  It works as an inline function.  Thanks.