Color legend for grid panel in ExtJS4

十年热恋 提交于 2019-12-02 04:24:51

I've had to do something similar.

I applied a "color" class to the cell based on the value using the column's renderer config.

In my case the value determined the color of the cell.

Here is the renderer:

// ... other column configs
renderer: function(value, meta, record) {
    switch(value) {

        case 1 : 
            meta.tdCls = 'orange-cell';
            break;

        case 2 : 
            meta.tdCls = 'light-orange-cell';
            break;

        case 3 : 
            meta.tdCls = 'green-cell';
            break;   
    }

    // I only had a color in my cell without any kind of value
    // so didn't include the following return statement. I added it here
    // just so you would know that you can have it also.
    return value;
}

The CSS classes looked like this:

.orange-cell {
    background-color: #ffbb22 !important;
}
.light-orange-cell {
    background-color: #33cc55 !important;
}
.green-cell {
    background-color: #ffeecc !important;
}

This is working fine with ExtJS 4.1.0

Add something like that to your grid definition:

viewConfig: {
  getRowClass: function(record, rowIndex, rowParams, store){
    return record.get("valid") ? "row-valid" : "row-error";
  }
}

See http://docs.sencha.com/ext-js/4-0/#!/api/Ext.view.Table-method-getRowClass for more details.

Note: That would work for individual rows. Do you really need cell-by-cell coloring?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!