Search code examples
javascriptextjsradio-buttonextjs6gridpanel

ExtJS GridPanel with radiobutton on the columns


So i have an usual grid, with some columns:

                  {
                        xtype          : 'gridpanel',
                        mode           : "MULTI",
                        region         : 'center',
                        title          : "grid",
                        id             : 'datagridResult',  
                        margin         : '10 5 5 5',

                    columns : [
                               {
                                   xtype    : 'gridcolumn',
                                   dataIndex: 'TEST',
                                   flex     : 0.25
                               },   
                               {
                                   xtype    : 'gridcolumn',
                                   dataIndex: 'Test2'
                                   flex     : 2
                               },   
                               //...

What i want is to add 3 more columns which are radiobuttons (one button per column). I tried something like this:

                             {
                                   xtype    : 'gridcolumn',
                                   text     : "FOR"
                                   dataIndex: 'for',
                                   flex     : 1,
                                   editor: { 
                                        xtype     : 'radiofield',
                                        name      : 'Regex',
                                        inputValue: 'Checked'
                                    },
                               }

And it doesn't work. So i am here to ask any sugestions.


Solution

  • And it doesn't work. So i am here to ask any sugestions

    In ExtJS have xtype :'widgetcolumn'. A widget column is configured with a widget config object which specifies an xtype to indicate which type of Widget or Component belongs in the cells of this column.

    I have created an Sencha Fiddle demo. It will show how is working. Hope this will help you.

    Ext.create('Ext.data.Store', {
        storeId: 'simpsonsStore',
        fields: ['name', 'email', 'phone', {
            name: 'checked',
            type: 'boolean',
            defaultValue: true
        }],
        data: [{
            name: 'Lisa',
            email: '[email protected]',
            phone: '555-111-1224'
        }, {
            name: 'Bart',
            email: '[email protected]',
            phone: '555-222-1234'
        }, {
            name: 'Homer',
            email: '[email protected]',
            phone: '555-222-1244'
        }, {
            name: 'Marge',
            email: '[email protected]',
            phone: '555-222-1254'
        }]
    });
    
    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [{
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        }, {
            text: 'Phone',
            dataIndex: 'phone'
        }, {
            text: 'Status',
            width: 150,
            xtype: 'widgetcolumn',
            dataIndex: 'checked',
            onWidgetAttach: function (column, widget, record) {
                widget.down(`[inputValue=${record.get('checked')}]`).setValue(true);
            },
            widget: {
                xtype: 'radiogroup',
                items: [{
                    boxLabel: 'Yes',
                    inputValue: true
                }, {
                    boxLabel: 'No',
                    inputValue: false
                }]
            }
        }],
        height: 200,
        width: 400,
        renderTo: Ext.getBody()
    });