rubio
rubio

Reputation: 966

Change background color of row extjs4

I have a grid named 'grid' and onload there are rows being insert into the grid. Some Rows will be in green will be successfully input rows while rows with a background color of red will have errors. I had it working at some point but the error rows would be added to the grid w their background color red. Then when i tried to add a new row to enter new data into that all the rows went white. And then that stopped working all together. I've tried

 store.insert(0, r).addClass('error-row'); 

and

 Ext.fly(grid.getView().getRow(0)).addClass('error-row');

and

var cls ='error-row'
                            addRowClass : function(rowId, cls) {
                                            var row = this.getRow(rowId);
                                            if (row) {
                                                this.fly(row).addClass(cls);
                                            }
                                        }

and

grid.getView().getRowClass = function(record, index, rp ,store) {

                                return 'error-row';
                                     };

I'm unsure of what to do.

css

 <style>
    .error-row .x-grid-cell {
    background-color: #990000 !important;
    }

    .new-row .x-grid-cell {
    background-color: #F5F2F3 !important;
    }


</style>

Upvotes: 3

Views: 5531

Answers (1)

phatskat
phatskat

Reputation: 1815

The viewConfig property should point you in the right direction - using code from Ext's sample for grid, adding:

  • cls field to define a class for a record
  • viewConfig property to the grid's configuration

The code looks like this:

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone', 'cls'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"[email protected]",  "phone":"555-111-1224", "cls":"new-row"  },
        { 'name': 'Bart',  "email":"[email protected]",  "phone":"555-222-1234", "cls":"new-row" },
        { 'name': 'Homer', "email":"[email protected]",  "phone":"555-222-1244", "cls":"new-row"  },
        { 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254", "cls": "error-row"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    id: 'MyGrid',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { header: 'Name',  dataIndex: 'name'},
        { header: 'Email', dataIndex: 'email', flex: 1},
        { header: 'Phone', dataIndex: 'phone'}
    ],
    viewConfig: {
        getRowClass: function(record, rowIndex, rowParams, store){
            return record.get('cls');
        }
    },
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});

Upvotes: 4

Related Questions