frosty
frosty

Reputation: 5370

selecting the first record of grid from controller in ext 4

I'm trying to select the first row of my grid. However the following gives me

"views is undefined"

  onLaunch: function () {
        var partsStore = this.getPartsStore();
        partsStore.load({
            callback: this.onPartsLoad,
            scope: this
        });
    },
    onPartsLoad: function (selection) {

        var grid = Ext.getCmp('partsViewGrid');
        grid.getSelectionModel().select(0);
        var form = Ext.getCmp('partForm');
        form.loadRecord(selection[0]);
    },

My view

Ext.define('Pandora.view.PartsList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.partslist',
    store: 'Parts',
    initComponent: function () {
        this.id = "partsViewGrid";
        this.height = 400;
        this.xtype = 'gridpanel';
        this.border = 0;
        this.columns = [
            {
                xtype: 'gridcolumn',
                id: 'description',
                dataIndex: 'Name',
                text: 'Descriptfion'
            },
            {
                xtype: 'gridcolumn',
                id: 'done',
                dataIndex: 'Completed',
                text: 'Done',
                renderer: renderProduct
            }
        ];

        this.callParent();
    }
});

Upvotes: 1

Views: 9872

Answers (1)

egerardus
egerardus

Reputation: 11486

If you just want one record you don't need the array "selection[0]" in there. In ExtJs 4.x this always works for me:

grid.getSelectionModel().select(0)

Upvotes: 4

Related Questions