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

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

本文关键字:颜色 extjs4 记录 数据库      更新时间:2023-09-26

我正在尝试根据数据库表中的字段值更改记录背景颜色,但是我没有成功。知道是什么阻止了这种变化吗?我的数据库中的字段名称是状态。

  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:

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

请注意,推杆:

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

将更改背景颜色。

您是否尝试过在网格面板上使用渲染?在这种情况下,您也可以尝试使用 tpl。状态值可以在呈现函数中使用,以返回行的不同值。设置样式属性应该可以解决问题。

你可以试试这个

{
    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'
}