更改行extjs4的背景颜色

Change background color of row extjs4

本文关键字:背景 颜色 extjs4      更新时间:2023-09-26

我有一个名为"grid"的网格,加载时有行插入到网格中。某些绿色行将成功输入行,而背景色为红色的行将出现错误。我在某个时候让它工作了,但错误行会被添加到背景色为红色的网格中。然后,当我试图添加新行以输入新数据时,所有的行都变成了白色。然后这一切都停止了。我试过

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

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

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

grid.getView().getRowClass = function(record, index, rp ,store) {
                                return 'error-row';
                                     };

我不知道该怎么办。

css

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

</style>

viewConfig属性应该为您指明正确的方向-使用Ext的网格示例中的代码,添加:

  • cls字段,用于定义记录的类
  • 网格配置的viewConfig属性

代码如下:

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone', 'cls'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224", "cls":"new-row"  },
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234", "cls":"new-row" },
        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244", "cls":"new-row"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "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()
});