How to change text color of only one line in ExtJS grid?

I created the following ExtJS grid.

I want to change the text color of all cells in row two .

However, I can learn how to change the color of all cells in all rows , including the title text, as shown here:

var myData = [
    [4, 'This is a whole bunch of text that is going to be word-wrapped inside this column.', 0.24, 3.0, '2010-11-17 08:31:12'],
    [16, 'Computer2-this row should be red', 0.28, 2.7, '2010-11-14 08:31:12'],
    [5, 'Network1', 0.02, 2.5, '2010-11-12 08:31:12'],
    [1, 'Network2', 0.01, 4.1, '2010-11-11 08:31:12'],
    [12, 'Other', 0.42, 5.0, '2010-11-04 08:31:12']
];

var myReader = new Ext.data.ArrayReader({}, [{
        name: 'id',
        type: 'int'
    }, {
        name: 'object',
        type: 'object'
    }, {
        name: 'status',
        type: 'float'
    }, {
        name: 'rank',
        type: 'float'
    }, {
        name: 'lastChange',
        type: 'date',
        dateFormat: 'Y-m-d H:i:s'
    }]);

var grid = new Ext.grid.GridPanel({
    region: 'center',
    style: 'color:red', //makes ALL text in grid red, I only want one row to be red
    store: new Ext.data.Store({
        data: myData,
        reader: myReader
    }),
    columns: [{
            header: 'ID',
            width: 50,
            sortable: true,
            dataIndex: 'id',

            hidden: false

        }, {
            header: 'Object',
            width: 120,
            sortable: true,
            dataIndex: 'object',
            renderer: columnWrap

        }, {
            header: 'Status',
            width: 90,
            sortable: true,
            dataIndex: 'status'
        }, {
            header: 'Rank',
            width: 90,
            sortable: true,
            dataIndex: 'rank'
        }, {
            header: 'Last Updated',
            width: 120,
            sortable: true,
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s'),
            dataIndex: 'lastChange'
        }],
    viewConfig: {
        forceFit: true
    },
    title: 'Computer Information',
    width: 500,
    autoHeight: true,
    frame: true,
    listeners: {
        'rowdblclick': function(grid, index, rec){
            var id = grid.getSelectionModel().getSelected().json[0];
            go_to_page('edit_item', 'id=' + id);
        }
    }
});

What do I need to do to change the text color only for cells in the second row?

+5
source share
2 answers

not sure if this helps, but you can try. I tried locally, it changes the color of all the characters in the 2nd line.

Add a listener to the grid:

listeners:{
    viewready: function(g){
        g.getView().getRow(1).style.color="#f30";
    }
}

" viewready, div getRow() GridView. Javascript ( , )

, , . , . .

+4

getRowClass, GridPanel viewConfig. API GridPanel:

   viewConfig: {
        forceFit: true,

   //   Return CSS class to apply to rows depending upon data values
        getRowClass: function(record, index) {
            var c = record.get('change');
            if (c < 0) {
                return 'price-fall';
            } else if (c > 0) {
                return 'price-rise';
            }
        }
    },

GridView , API :

getRowClass( Record record, Number index, Object rowParams, Store store )

CSS- . , rowParams. CSS ( "" ) div. , (, "my-class another-class" ).

CSS index.

+8

All Articles