PDA

View Full Version : [Solved]selectRow not working as expected



michaelc
12 Nov 2009, 11:21 AM
I have a grid that is being refreshed every 10 seconds, problem is I want to keep the selected rows selected.

I thought this would work but is seems to drop the selected row with each iteration.

I see the log show the row selected then it's unselected after the reload.

Why does the row not stay selected ?


var task = {
run: function(){
var toolSelected = false;
console.log('enter run function');
console.log('select count is ' + gridTool.getSelectionModel().getCount());
if (gridTool.getSelectionModel().hasSelection()){
var record = gridTool.getSelectionModel().getSelected();
var toolSelected = true;
}

gridTool.store.load();
if (toolSelected){
var selectIndex = gridTool.store.find('deviceName',record.get('deviceName'));
console.log('select index is ' + gridTool.getSelectionModel().getCount());
if (selectIndex > 0){
gridTool.getSelectionModel().selectRow(selectIndex);
console.log('select is ' + gridTool.getSelectionModel().hasSelection());
}

}

gridClass.store.load();
},
interval: 1000 * 8 //8 second
}
Ext.TaskMgr.start(task);

12 Nov 2009, 11:44 AM
Michael,

i would not call store.load twice.

Also, i would only attempt to make a selection after the load has taken place (think load event).

Does this make sense?

michaelc
12 Nov 2009, 12:51 PM
Michael,

i would not call store.load twice.

Also, i would only attempt to make a selection after the load has taken place (think load event).

Does this make sense?

Not calling store load twice it's 2 different stores.
what I want is to keep the selection in the grid, unless the row no longer exist in the grid after it's been reloaded.

I found my answer, it's a timing issue.
the selectRow is occurring to soon after the load, I modified to
setTimeout(function() {gridTool.getSelectionModel().selectRow(selectIndex)}, 500);

and it worked.

now the real answer I would expect is
to define a before load and after load on that store
in the before load capture if a row is selected and save the data.
in the after load if there is a data value saved find it in the store and reselect the row.

gridTool.getSelectionModel().selectRow(selectIndex);

12 Nov 2009, 12:56 PM
Sorry dude, i missed that. You should not use a setTimeout. You're bound to the response time of the server and is a very rigid solution.

Again, setup a "load" event handler that helps retain the selections.

michaelc
12 Nov 2009, 1:01 PM
Sorry dude, i missed that. You should not use a setTimeout. You're bound to the response time of the server and is a very rigid solution.

Again, setup a "load" event handler that helps retain the selections.

agreed, see my "Real answer"