Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs ComboBox inside grid

Tags:

combobox

extjs

I have a grid with some data (users list). For each row I have many actions such as update, delete, activate, suspend, view orders you name it.

Instead of placing so many buttons which will fill more than 400-500 pixels I want to place a combobox with an action applied to each field.

The problem is that I can't simply render a combobox in a column row just like that or I'm missing something? Can someone shed some light on this please?

new Ext.grid.GridPanel({
    region: 'center',
    id: 'usersGrid',
    store: store,
    stripeRows: true,
    autoExpandColumn: 'username',
    columns: [{
            // username
        },{
            // email
        },{
            // last seen
        },{
            //  actions combo, it won't show
            header: '',
            width: 220,
            fixed: true,
            hideable: false,
            dataIndex: 'actions',
            renderer: new Ext.form.ComboBox({
                store: new Ext.data.SimpleStore({
                    id: 0,
                    fields: ['abbr', 'action'],
                    data: [
                        ['suspend', 'Suspend'],
                        ['activate', 'Activate'],
                        ['update', 'Update'],
                        ['delete', 'Delete']
                    ]
                }),
                displayField: 'action',
                valueField: 'abbr',
                mode: 'local',
                typeAhead: false,
                triggerAction: 'all',
                lazyRender: true,
                emptyText: 'Select action'
            })
        }
    ]
});
like image 657
Roy Rodgers Avatar asked Jan 21 '23 20:01

Roy Rodgers


1 Answers

  1. Convert Grid to Editable Grid
  2. Add editor config in columns instead of 'renderer'. Find below the altered code.
new Ext.grid.EditorGridPanel({
    region: 'center',
    id: 'usersGrid',
    store: store,
    stripeRows: true,
    autoExpandColumn: 'username',
    columns: [{
        // username
    }, {
        // email
    }, {
        // last seen
    }, {
        //  actions combo, it won't show
        header: '',
        width: 220,
        fixed: true,
        hideable: false,
        dataIndex: 'actions',
        editor: {
            xtype: 'combo',
            store: new Ext.data.ArrayStore({
                fields: ['abbr', 'action'],
                data: [
                    ['suspend', 'Suspend'],
                    ['activate', 'Activate'],
                    ['update', 'Update'],
                    ['delete', 'Delete']
                ]
            }),
            displayField: 'action',
            valueField: 'abbr',
            mode: 'local',
            typeAhead: false,
            triggerAction: 'all',
            lazyRender: true,
            emptyText: 'Select action'
        }
    }]
});
like image 131
shivashankar Avatar answered Jan 28 '23 14:01

shivashankar