简体   繁体   English

根据数据库值extjs4.2更改记录的颜色

[英]Changing the color of a record based on database value, extjs4.2

I'm trying to change the records background color based on a field value in my database table, however i'm not being successful in doing that. 我正在尝试基于数据库表中的字段值更改记录的背景色,但是我这样做没有成功。 Any idea what could be preventing this change? 知道什么可以阻止此更改吗? Name of the field in my database is STATUS. 我的数据库中的字段名称为STATUS。

  grid = new Ext.grid.GridPanel({
                        region:'center',
                        store: gridStore,
                        cm: colModel,
                        stripeRows: true,
                        sm: _selctionModel,
                        bbar:paging,
                        viewConfig:
                        {
                            forceFit: true,
                            headersDisabled:false,
                            stripeRows: false, 
                            getRowClass: function(record) { 
                                return record.get('STATUS') == 'OP' ? 'child-row' : 'adult-row'; 

                            } 
                        },

CSS: CSS:

.child-row .x-grid-cell-inner{
    background-color:red;
    color:red;
}

.adult-row .x-grid-cell-inner{
    background-color:blue;
    color:blue;
}

please note that putting: 请注意:

.x-grid-cell-inner{
        background-color:blue;
        color:blue;
    }

will change the background color. 会改变背景颜色。

Have you tried to use a render on your grid panel? 您是否尝试过在网格面板上使用渲染? You also can try to use a tpl in this case. 在这种情况下,您也可以尝试使用tpl。 The status value can be used in a render function to return different values of the rows. 状态值可以在渲染函数中使用,以返回不同的行值。 Setting style properties you should solve your problem. 设置样式属性应该可以解决您的问题。

you can try this 你可以试试这个

{
    xtype: 'gridcolumn',
    renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
        metaData.tdCls = (value=="OP")?'adult-row':'adult-row';
        return value;
    },
    dataIndex: 'status',
    text: 'STATUS'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM