PDA

View Full Version : Calling GridPanel.store.load, I lose selected item



sublimespot
5 Mar 2008, 3:42 PM
I have a multi panel application. A grid in one panel and a form in one panel.
When I update some data via a form, I want to update the grid with this information.
So I call GridPanel.store.load() which refreshes the grid.
However, now I've lost my selected item. I would like to have the previously selected item remain selected.

evant
5 Mar 2008, 3:44 PM
Before you reload the store, keep track of any items of selected. Once the load has completed, go through and reselect the appropriate rows.

sublimespot
6 Mar 2008, 10:18 AM
This is not working. Can someone point me in the right direction. Thanks


// Store the selected item
var oItems = grid.selModel.getSelections();

// Refresh the customer grid
grid.store.load();

// Restore the selected item
grid.selModel.selectRecords(oItems);

sublimespot
6 Mar 2008, 10:30 AM
I think I see what is happening. The refresh (grid.store.load) is happening asynchronously and is occurring after the selectRecords()

sublimespot
6 Mar 2008, 11:07 AM
Tried with a callback and still having trouble
I made a global variable for the items (g_items) just until I get the code working.



g_items = grid.selModel.getSelections();

// Refresh the customer grid
grid_customer.store.load({
callback: function (){
//grid.selModel.selectAll(); // This works
grid.selModel.selectRecords(g_items, false); // not working
//grid.selModel.selectRecords([g_items], false); // not working
//grid.selModel.selectRecords([g_items[0]], false); // not working
}
});

sublimespot
6 Mar 2008, 1:07 PM
When I changed to a singleSelect selection model,


sm: new Ext.grid.RowSelectionModel({singleSelect: true}),

the following line of code worked:


g_items = grid.selModel.getSelections();

// Refresh the customer grid
grid_customer.store.load({
callback: function (){
grid_customer.selModel.selectRecords(g_items[0], false);
grid_customer.selModel.selectAll();
}
});