【问题标题】:Change background color of row extjs4更改行extjs4的背景颜色
【发布时间】:2012-02-25 05:38:57
【问题描述】:

我有一个名为“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>

【问题讨论】:

    标签: javascript extjs4 background-color


    【解决方案1】:

    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()
    });
    

    【讨论】:

    • 是的,在这方面的文档有点稀疏 - 它曾经 (IIRC) 出现在 Ext 2.x/3.x 网格常见问题解答中,但我没有看到太多提及它在 4.x 文档中。
    • 在模型中拥有特定于视图(类)的数据似乎很奇怪。
    • 这只是我以前使用的一种方法,并且效果很好。可能还有其他的,所以请随意改进或添加您自己的:]
    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    相关资源
    最近更新 更多