Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs checkboxselectionmodel

Tags:

extjs

I am using GridPanel w/CheckboxSelectionModel for item selection. In the edit mode, where some options were already picked, I am trying to pre-select the rows when loading the form.

...
store.load();
//curSelections is an array containing the some ForeingKey IDs of the selected records.
...

for (var i = 0; i < curSelections.length; i++) {
    console.log('found personel ' + curSelections[i] + ' at ', 
                 store.findExact('Id', curSelections[i]));
    selectedRecords.push(store.findExact('Id', curSelections[i]));
}
//everything is fine according to console log.
checkGrid.getSelectionModel().selectRecords(selectedRecords, true);
formWin.show();

this does not work.

I try to call" selectRecords" also on some other page/form events, but none of those even fires.

grid.addListener('show',
grid.on('show',
formWin.on('activate',
formWin.on('show',....

some of the grid code

var sm = new Ext.grid.CheckboxSelectionModel({
        singleSelect: false,
        sortable: false,
        checkOnly: true
    });
    checkGrid = new Ext.grid.GridPanel({
        xtype: 'grid',
        store: obPersonelStore,
        loadMask: true,
        layout: 'fit',
        height: 120,
        id: 'grdIsBirimiPersonelListesi',

        columns: [
            sm,
            {

I am missing something simple, but dont know what it is. Any kind of help is greatly appreciated.

like image 210
hazimdikenli Avatar asked Apr 13 '26 03:04

hazimdikenli


2 Answers

Store.findExact returns a numeric index. SelectionModel.selectRecords expects an array of Record objects. Have you tried selectRows instead? Either that, or use store.getAt to retrieve records by index to pass to selectRecords().

like image 105
Brian Moeskau Avatar answered Apr 16 '26 00:04

Brian Moeskau


try:

var store = new Ext.data.Store({
  ...
});
var grid = new Ext.grid.GridPanel({
  store: store,
  ...
});
store.on('load', function() {
  grid.getSelectionModel().selectFirstRow();
});
store.load();
like image 33
Zeratul Avatar answered Apr 16 '26 02:04

Zeratul