PDA

View Full Version : Highlighting Programmatically Selected Grid Item



hornfrog
31 Jan 2012, 7:47 PM
I have a grid that gets refreshed via store.load(). Before the load is executed, I save the selected items because I want them reselected afterward. In the load callback, I select the items previously selected and it seems to work (selected items set per FireBug). However, the items are no longer highlighted in the grid. Why doesn't setting the item selections automatically highlight, and how can I work around this to get the items highlighted and scrolled into view?

selectedRecs = grid.selModel.selected.items[0];
jobDefsStore.load({
scope: this,
callback: function (records, operation, success) {
// this works (items get selected), but they are no longer highlighted
grid.selModel.select(selectedRecs, false, false);
}
});

Thanks.

Oh, and I noticed in the online docs that the grid.getView() returns a Ext.View.Table, and that object is documented to have a getSelectedRecords() member function. However, when in FireBug, that does not appear to be true. Do the docs need to be updated?

vietits
31 Jan 2012, 8:46 PM
After loading, all records in the store are new instances and they are not the same as before loading. Let try the following code. Hope this will solve your problem.


// Save id of selected records
var selectedIds = [];
var selectedRecs = grid.getSelectionModel().selected;

selectedRecs.each(function(record){
selectedIds.push(record.getId());
});
jobDefsStore.load({
scope: this,
callback: function (records, operation, success) {
var selectedRecs = [];
Ext.Array.each(selectedIds, function(recordId){
selectedRecs.push(jobDefsStore.getById(recordId));
});
grid.getSelectionModel().select(selectedRecs);
}
});

hornfrog
31 Jan 2012, 10:50 PM
Ahhh, I see what you mean. Thanks for the info - that seems to work.