PDA

View Full Version : SelectionModel and store load



mtobar
11 Mar 2013, 6:55 PM
Hi, everyone... i used a gridselectionmodel like this:

checkBox.on('rowselect', function(a,rowIndex,record){
dosomething();
});

var colModel = new Ext.grid.ColumnModel({
columns: [
checkBox]
});


var grid = new Ext.grid.GridPanel({
store : store,
id : 'gridMovil',
name : 'gridMovil',
selModel : checkBox,
columns : colModel.columns
});


I added two listeners

store.on('beforeload',function(records){
Ext.each(grid.getSelectionModel().getSelections(),function(record){
rows.push(record.get('id_mobile'));
})
});

store.on('load',function(records){
grid.getSelectionModel().selectRows(rows);
});

but when loading the store, no rows are selected. Anyone have any ideas??.


thanks

mitchellsimoens
13 Mar 2013, 1:39 PM
Did you set a breakpoint to see what's going on like if the rows array is still valid after store load?

willigogs
13 Mar 2013, 3:30 PM
Or alternatively just get the records using sm.getSelections(), then repopulate the selections using sm.selectRecords().

mtobar
13 Mar 2013, 5:56 PM
Thanks for all... finally use this in the listeners and go fine:


store.on('beforeload',function(records){
Ext.each(grid.getSelectionModel().getSelections(),function(record){
rows.push(record.get('id_mobile'));
})
});

store.on('load',function(){
var index;
for(var i=0; i < rows.length ; i++){
index = store.findExact('id_mobile', rows[i],0);
if(index != -1)
grid.getSelectionModel().selectRow(index, true);
}
});