Ben Irving
Ben Irving

Reputation: 493

Default value in grid

I have a grid/list:

items: [
                    {
                        xtype: 'gridpanel',
                        reference: 'list',
                        resizable: false,
                        width: 200,
                        title: '',
                        forceFit: true,
                        bind: {
                            store: '{schedules}'
                        },
                        columns: [
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'revision',
                                text: 'Revision'
                            }
                        ],

I want to add a listener so that the record at index 0 in the store is selected by default.

I've tried playing with selModel but its not working as intended.

Upvotes: 0

Views: 60

Answers (2)

Tarabass
Tarabass

Reputation: 3152

Listen to the store load event (as example in the controller):

onLaunch: function () {
    var me = this,
        grid = me.getGrid(),
        store = me.getGroupsStore();

    store.load({
        callback: function(records, operation, success) {
            grid.getSelectionModel().select(0);
        },
        scope: this
    });
},

Upvotes: 0

Greendrake
Greendrake

Reputation: 3734

Do it on viewready event:

{
    xtype: 'gridpanel',
    listeners: {
        'viewready': function(g) {
            g.getSelectionModel().select(0);
        }
    },
    // ....
}

Example: https://fiddle.sencha.com/#fiddle/qe6

Upvotes: 2

Related Questions