更改行extjs4的背景颜色 [英] Change background color of row extjs4

查看:160
本文介绍了更改行extjs4的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为"grid"的网格,并在加载时将一些行插入到网格中.一些行将显示为绿色,将成功输入行,而背景色为红色的行将出现错误.我可以在某个时候使用它,但是错误行将被添加到带有红色背景色的网格中.然后,当我尝试添加新行以向其中输入新数据时,所有行都变成白色.然后,这一切都停止了.我已经尝试过

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'); 

 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的示例示例中的代码进行网格处理,并添加:

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

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

这篇关于更改行extjs4的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆