0

I have a grid panel like:

Ext.define('Demo.view.main.content.source.Ex', {
    extend: 'Ext.grid.Panel',
    requires: [
        'Demo.store.main.content.source.Ex',
        'Demo.view.main.content.source.ExController',
    ],

    xtype: 'app-main-content-ex',

    title: 'Example',

    store: 'Demo.store.main.content.source.Ex',

    controller:'main-content-source-ex',

    //multiSelect: false,
    columnLines: true,

    initComponent: function() {
        var store = Ext.create('Demo.store.main.content.source.Ex', {
            storeId: 'app-main-content-source-exstore'
        });
        Ext.apply(this, {
            store: store
        });

        this.columns= [

            {
                text     : 'Driver Name',
                flex     : 3,
                sortable : false,
                dataIndex: 'name'
            },
            {
                xtype: 'gridcolumn',
                getEditor: function(record) {
                    console.log(record.get('state'));
                    var value;
                    if (record.get('state') == 'free') {

                        value = 'xf09c@FontAwesome'
                    } else {
                        value = 'xf023@FontAwesome'
                    }
                    return Ext.create('Ext.grid.CellEditor', {
                        field:{
                            xtype: 'image',
                            glyph: value
                        }
                    });
                },
                 text     : 'State',
                flex    : 1,
                dataIndex: 'state'
            }]

        this.callParent();
    },
    listeners:{
        afterRender: 'setUpInfo'
    }
});

I am loading the store of that in grid afterrender event. I want to set the image in the State column based on the value of state(free/busy). Its not working.

How should I do it?

Abhinav Bhardwaj
  • 160
  • 2
  • 16

1 Answers1

0

You can use a renderer to augment the displayed value of the cell.

        columns: [{
            xtype: 'gridcolumn',
            dataIndex: 'name',
            text: 'Driver Name',
            flex: 1,
            editor: {
                xtype: 'textfield'
            }
        }, {
            xtype: 'gridcolumn',
            renderer: function(value) {
                if (value == 'free') {

                    return 'xf09c@FontAwesome'
                } else {
                    return 'xf023@FontAwesome'
                }
            },
            getEditor: function(record) {
                var value;
                if (record.get('state') == 'free') {

                    value = 'xf09c@FontAwesome'
                } else {
                    value = 'xf023@FontAwesome'
                }
                return Ext.create('Ext.grid.CellEditor', {
                    field: {
                        xtype: 'image',
                        glyph: value
                    }
                });
            },
            text: 'State',
            flex: 1,
            dataIndex: 'state'
        }]

Docs: - http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.grid.column.Column-cfg-renderer

Rob Schmuecker
  • 8,934
  • 2
  • 18
  • 34