PDA

View Full Version : Finding rowIndex of that row given rowId of row



rahulmca1@gmail.com
22 Feb 2007, 7:17 AM
Hi,



Given SelectedRowId of a datagrid how can I find rowIndex of that row.

Now I am using something like this




SelectedRowId = searchSelModel.getSelectedRowIds();
for( i = 0 ; i < DataModel.getRowCount(); i=i+1){
if (DataModel.getRowId(i) == SelectedRowId ){
rowIndex = i;
break;
}
}






It is not efficent and takes too much time if I have say 200 rows and the row to be searched lies between 140-200

Waiting for ur response.

Thankyou

tryanDLS
22 Feb 2007, 8:18 AM
The row object returned by by getSelectedRows(), has a rowIndex property. Also, when doing looping like this, you'll see some perfomance gain by coding with local vars. This prevents searching up the scope chain looking for i. Also, you only do getRowCount() once.



for (var i=0, len=dm.getRowCount(); i<len; i++) {
...
}