Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何根据值的变化更改extjs网格单单元格背景颜色?_Css_Extjs_Grid_Extjs4_Row - Fatal编程技术网

Css 如何根据值的变化更改extjs网格单单元格背景颜色?

Css 如何根据值的变化更改extjs网格单单元格背景颜色?,css,extjs,grid,extjs4,row,Css,Extjs,Grid,Extjs4,Row,要更改整行背景色,我们可以使用getRowClass,但是如何只对一个单元格和特定列执行相同的逻辑…有什么想法吗 //EXTJS viewConfig: { getRowClass: function(record, index) { var c = record.get('change'); if (c < 0) { return 'price-fall'; } else if (c > 0) {

要更改整行背景色,我们可以使用getRowClass,但是如何只对一个单元格和特定列执行相同的逻辑…有什么想法吗

//EXTJS
viewConfig: {
    getRowClass: function(record, index) {
        var c = record.get('change');
        if (c < 0) {
            return 'price-fall';
        } else if (c > 0) {
            return 'price-rise';
        }
    }
}

//CSS
.price-fall { 
        background-color: #FFB0C4;
}
.price-rise {
        background-color: #B0FFC5;
}
但这样的话,当背景从白色变为彩色时,网格就会变形

还有其他想法吗

编辑
将自定义css应用于列后,如何在短时间内删除相同的css,使其在值更改时闪烁一次?类似于
setTimeout(“remove-css()”,1000)或使用
Ext.Function.defer(删除css,1000)

有什么想法吗?

我建议使用
getRowClass
对需要的列应用额外的cls:


这是。

当我做另一件事时,我还发现了另一种方法

在列定义中:

{
    dataIndex: 'invoicePrintedFlag', 
    header: 'Fatura',
    width: 50,
    renderer : function(value, metadata, record) {
        if (record.get('invoiceAddressId') != null){
            metadata.tdCls = metadata.tdCls +" alertedCell";
        }

        return '<span class="iconbox icon-'+ value +'"></span>';
    }
}
如果您使用样式,它将添加到TD内的content DIV中

<td class=" x-grid-cell x-grid-cell-gridcolumn-1067" id="ext-gen1432">
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style=" text-align: left;" id="ext-gen1426">
    // Content comes here
    </div>
</td>

您还可以根据需要返回html。

这在Ext 2.3中适用,但需要设置metadata.css而不是metadata.tdClsI不能使用row类,因为我的值是我的颜色。所以你的解决方案对我有效。唯一的问题是行选择覆盖了td背景。有什么想法吗?
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {

  metaData.tdAttr = 'style="background-color:#b0e987;color:black;"';

  value=Ext.util.Format.number(value, '$ 0,000.00');

  return value;

},
{
    dataIndex: 'invoicePrintedFlag', 
    header: 'Fatura',
    width: 50,
    renderer : function(value, metadata, record) {
        if (record.get('invoiceAddressId') != null){
            metadata.tdCls = metadata.tdCls +" alertedCell";
        }

        return '<span class="iconbox icon-'+ value +'"></span>';
    }
}
metadata: Object {tdCls: "", style: ""} 
<td class=" x-grid-cell x-grid-cell-gridcolumn-1067" id="ext-gen1432">
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style=" text-align: left;" id="ext-gen1426">
    // Content comes here
    </div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1067   alertedCell " id="ext-gen1462">
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="; text-align: left;" id="ext-gen1463">
    // Content comes here
    </div>
</td>
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {

  metaData.tdAttr = 'style="background-color:#b0e987;color:black;"';

  value=Ext.util.Format.number(value, '$ 0,000.00');

  return value;

},