tags:

views:

2636

answers:

2

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.

A: 

I'm not 100% certain what you want to achieve. You said:

I find the selected rows of the entire list

Do you mean you want to select every row? In that case you can use the selectAll() method of the CheckboxSelectionModel.

If you only want to select some of the rows then I'd need to see the code you're using to get those rows in the first place but it could be that you want to use selectRecords() rather than selectRows().

colinramsay
it was a typo, I added more of the code in the original post.I am not adding the entire code, coz it wont make much sense.
hazimdikenli
A: 

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().

bmoeskau
alright, for some reason I was thinking that selectRecords was expecting the row indexes. Now the funny thing is, it works, they are selected, but when the loading pane (spinning image) disappears, selections are cleared.
hazimdikenli
You might try moving the selection logic into a handler for the store.load event to make sure the store loading is complete first, e.g., store.on('load', function() { // selection logic });
bmoeskau
Thank you very much. It resolved the problem. :)You've been very helpfull, thanks again.
hazimdikenli