javascript - 更改行 extjs4 的背景颜色

标签 javascript extjs4 background-color

我有一个名为“grid”的网格,onload 中有行被插入到网格中。 Some Rows 将是绿色的将成功输入行,而背景颜色为红色的行将有错误。我让它在某个时候工作,但错误行将被添加到背景颜色为红色的网格中。然后,当我尝试添加一个新行以向其中输入新数据时,所有行都变白了。然后就停止了一起工作。我试过了

 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 字段为记录定义类
  • grid 配置的 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()
});

关于javascript - 更改行 extjs4 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9114496/

相关文章:

javascript - 删除值时将输入背景颜色更改为白色

使用 css() 更改背景颜色的 JavaScript 开关

javascript - 没有 jQuery 的 .html() 和 .append()

javascript - 我网站上的 Twitter 关注按钮 - Flash 的无样式内容

extjs - extjs 4 mvc 应用程序中的 View 路径不正确

javascript - 可以在 Extjs4 图表中制作 google 图表

javascript - Jquery 函数在窗口大小调整时不会改变

javascript - 当我与比特币平均服务器通信时,它显示 403 状态代码错误

javascript - Extjs 加载页面 : How to reduce the amount of background get uri requests

html - Span-within-a-span背景颜色优先级