PDA

View Full Version : row select of a previous selected row



pppswing
17 Nov 2010, 4:47 AM
Hello,

I want to keep a selected row when I'm doing a reload of the datastore.

But I'm loosing the selected row.

My grid has a rowselect listener. I tried without success :


myrow = dictionaries_grid.getSelectionModel().getSelected();
dictionaries_store.reload();
dictionaries_grid.getSelectionModel().selectRow(myrow);
dictionaries_grid.fireEvent('rowselect', dictionaries_grid, myrow);

How can I do ?

Thanks! :)

Graveworm
17 Nov 2010, 5:22 AM
If u have a server-side record id (for example from the db), u can store this and after the reload you can iterate through the records and select the record with the correct id (compared to the stored id). Sorry for the (very) bad english...

pppswing
17 Nov 2010, 5:40 AM
I tried this without success :


myrow = dictionaries_grid.getSelectionModel().getSelected();
myrowIndex = dictionaries_store.indexOf(myrow);
dictionaries_store.reload();
dictionaries_grid.getSelectionModel().selectRow(myrowIndex);
dictionaries_grid.fireEvent('rowselect', myrowIndex, myrow);

My row is not selected as it was !

Graveworm
17 Nov 2010, 6:00 AM
I would try it like this:


var actualId = 0;


myrow = dictionaries_grid.getSelectionModel().getSelected();
actualId = myrow.data.id;

reload store

dictionaries_store.reload();

in your data store need the load-listener

'load' : function( Store, Ext.data.Record[] records, options )
{

var recordsToSelect = new Array();
Ext.each(records, function(record) {
if(records.data.id = actualId)
{
recordsToSelect.push(record)
}
}, this);


dictionaries_grid.getSelectionModel().selectRecords(recordsToSelect);
}

It's untested and only a snippet. But maybe this helps you.

pppswing
17 Nov 2010, 8:57 AM
You were right, I have to select my row in the load listener because the store.load() is asynchronous, now it works fine !

in global scope


myrowIndex = 0;
firstload = 0;



in the form function


myrow = dictionaries_grid.getSelectionModel().getSelected();
myrowIndex = dictionaries_store.indexOf(myrow);
dictionaries_store.reload();

in the store


listeners: {
load: function() {
if(firstload==0){
firstload=1;
return;
}
dictionaries_grid.getSelectionModel().selectRow(myrowIndex);
}
}