更改行 extjs4 的背景颜色

发布于 2025-01-02 05:26:52 字数 1170 浏览 2 评论 0原文

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2025-01-09 05:26:52

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

  • 记录 viewConfig 属性定义一个类
  • cls 字段为网格配置中的

代码如下所示:

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

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()
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文