0

I am trying to add background color for 2 column in grid table. How can I do that?

I am aware of ExtJS 4 - How to add background colors to columns of a grid? , but I am looking for a specific property I can use rather than a function. Is there any property that I can configure to add background colors here instead?

Please find my code below-

var ALIASGRID = new Ext.grid.EditorGridPanel({
                store : ALIASGRIDStore,
                stripeRows : true,
                hideHeaders : true,
                id : "ALIASGRID",
                region : 'center',
                clicksToEdit : 1,
                autoHeight : true,
                viewConfig : {
                    markDirty : false
                },
                columnLines : true,
                columns : [ {
                    id : 'Test',
                    header : 'Test',
                    dataIndex : 'Test',
                    width : 30,
                    editor: {
                    xtype: 'textfield',
                    triggers: {
                        search: {
                            cls: 'x-fa fa-search',
                            handler: function (field, trigger, eOpts) {}
                                }
                            }
                        },
                    renderer : renderTooltipAndId
                }],
                listeners : {
                    beforeedit : function(grid) {
                        if (!attributeMgrEnabled) {
                            return false;
                        }
                        // console.log(grid);
                    }
                }
            });
            
var ALIASFOOTER = new Ext.grid.EditorGridPanel({
                enableHdMenu : false,
                id : 'ALIASFOOTER',
                height : 19,
                store : ALIASFOOTERStore,
                columns : [ {
                    id : 'Test',
                    header : 'Testing.',
                    resizable : false,
                    width : 30
                }]});           
                
                
// Table that shows empty rows & a footer
            var layoutTable1 = new Ext.Panel({
                width : 470,
                items : [ ALIASGRID, ALIASFOOTER ],
                renderTo : 'AliasTable'
            });

I have tried to use bodyStyle: 'background-color: #ff0000'; property but it did not work.

  • Does this answer your question? [How to add background-color for particular column in Grid using ext-js](https://stackoverflow.com/questions/75815585/how-to-add-background-color-for-particular-column-in-grid-using-ext-js) – hwsw Mar 24 '23 at 14:57

1 Answers1

0

You can use tdCls config on a column to define the class on individual cells of the respective column.

https://docs.sencha.com/extjs/7.6.0/classic/Ext.grid.column.Column.html#cfg-tdCls

Fiddle: https://fiddle.sencha.com/#fiddle/3n58&view/editor

  • Hi Devendra, small doubt is suppose if we configured tdCls : 'custom-color' then can we define custom-color in js file itself. – Pushpak Bannore Mar 23 '23 at 11:14
  • 1
    Yes, you can. const classDef = ['.custom-color','{background-color: red;}'] Ext.util.CSS.createStyleSheet(classDef.join('')); – hwsw Mar 24 '23 at 14:52