To change whole row background color we can use getRowClass, but how to do the same logic only for one cell, and particular column....any ideas?
//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;
}
EDIT:
There is a way of doing this with:
function change(val){
if(val > 0){
return '<div class="x-grid3-cell-inner" style="background-color:#B0FFC5;"><span style="color:green;">' + val + '</span></div>';
}else if(val < 0){
return '<div class="x-grid3-cell-inner" style="background-color:#FFB0C4;"><span style="color:red;">' + val + '</span></div>';
}
return val || 0;
}
and then just:
...
{header: 'Change', width: 75, sortable: true, renderer: change, dataIndex: 'change', align: 'center'}
...
but this way grid gets deformed on changes from white to colored background... ???
any other ideas?
EDIT
After custom css is applyed to the column, how to remove the same in a short period of time, so it appears to blink once when the value has changed? Something like setTimeout("remove-css()",1000);
or with Ext.Function.defer(remove-css, 1000);
Any ideas?
There is also another method I found when I am doing another thing;
In column definition:
you can use
renderer
if you manipulate cell completely, here is comesmetadata
:if you use style it will be added to content DIV inside TD
if you use
tdCls
, it will be added to classattr
of TDAlso you can return html as you want.
I suggest using
getRowClass
with applying extra cls to needed columns:CSS:
Here is demo.