extjs change grid cell background based on value

后端 未结 6 1440
刺人心
刺人心 2020-12-10 06:16

I applied a renderer to my grid-column, but the background color is not changing:

renderer: function(value, meta) {
    if (parseInt(value) > 0) {
                


        
相关标签:
6条回答
  • 2020-12-10 06:35

    you can set style in class like this:

    js:

    columns: {
            items: [
               {
                    ...
                    innerCls: 'column-ltr',
    
               }]
    

    css:

    .column-ltr{
       direction :rtl;
    }
    
    0 讨论(0)
  • 2020-12-10 06:43

    Inspired by Select Smile... this worked for me:

        var myRender = function (value, metaData, record, rowIndex, colIndex, store, view) {
            if (parseInt(value) < 0) {
                metaData.attr = 'style="background-color:#ffaaaa !important;"';
            }
            return value
        };
    

    and the field

    {id: 'dta', dataIndex: 'days_to_arrival', renderer: myRender}
    

    that's it.

    ps. done under ExtJS v2.2.1

    0 讨论(0)
  • 2020-12-10 06:43

    refer to these example

    Ext.onReady(function(){
        Ext.create('Ext.data.Store', {
            storeId:'simpsonsStore',
            fields:['name', 'email', 'change'],
            data:{'items':[
                { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "change":100  },
                { 'name': 'Bart', "email":"bart@simpsons.com", "change":-20  },
                { 'name': 'Homer', "email":"home@simpsons.com",  "change":23   },
                { 'name': 'Marge', "email":"marge@simpsons.com", "change":-11   }
            ]},
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'items'
                }
            }
        });
    
        Ext.create('Ext.grid.Panel', {
            title: 'Simpsons',
            store: Ext.data.StoreManager.lookup('simpsonsStore'),
            columns: [
                { header: 'Name',  dataIndex: 'name' },
                { header: 'Email', dataIndex: 'email', flex: 1 },
                { header: 'Change', dataIndex: 'change', tdCls: 'x-change-cell' }
            ],
            height: 200,
            width: 400,
            viewConfig: {
                getRowClass: function(record, index) {
                    var c = record.get('change');
                    if (c < 0) {
                        return 'price-fall';
                    } else if (c > 0) {
                        return 'price-rise';
                    }
                }
            },
            renderTo: Ext.getBody()
        });
    });
    

    CSS:

    .price-fall .x-change-cell {
        background-color: #FFB0C4;
        color:red;
    }
    .price-rise .x-change-cell {
        background-color: #B0FFC5;
        color:green;
    }
    
    0 讨论(0)
  • 2020-12-10 06:52

    Try this...

    renderer : function(value, meta) {
        if(parseInt(value) > 0) {
            meta.style = "background-color:green;";
        } else {
            meta.style = "background-color:red;";
        }
        return value;
    }
    

    It works for me.

    0 讨论(0)
  • 2020-12-10 06:59
    renderer: function (value, metaData) {
        if (parseInt(value) > 0) {
            metaData.tdStyle = 'background-color:#ffaaaa';
        }
        return value
    }
    
    0 讨论(0)
  • 2020-12-10 06:59

    Try

    .x-grid-cell.category-matching {
        background-color:green;
    }
    .x-grid-cell.category-not-matching {
        background-color:red;
    }
    
    0 讨论(0)
提交回复
热议问题