var summaryRow = grid.getView().getFeature(0);
styleObj = {
'background-color': '#c5c5c5'
};
summaryRow.view.el.setStyle(styleObj);
Change the color of summary row of grid in extjs
Question
I want to change the font as well as background color of the summary row of the grid.I have tried getting the summary row as :
var summaryRow = grid.view.el.down('tr.x-grid-row-summary');
Based on summaryRow I can set the style.But I am getting the value of summaryRow as null.Can anyone please point me to correct direction or am I missing something? Any help is appreciated.Thanks
Solution 2
OTHER TIPS
The documented way to do this would be the Summary Renderer, the best method for the summary renderer would be the tdCls or tdAttr properties:
text: 'Allocation %',
xtype: 'numbercolumn',
format: '00.00%',
dataIndex: 'allocationAmount',
summaryType: 'sum',
summaryRenderer: function (value, summaryData, dataIndex, rowIndex, colIndex, store, view) {
if (value > 100)
{
summaryData.tdCls = 'text-warning-high'
} else if (value === 100)
{
summaryData.tdCls = 'text-successful';
} else {
summaryData.tdCls = 'text-warning-low';
}
return Ext.String.format('Total: {0}%', value);
},
You can also use the tdAttr version like this:
summaryRenderer: function (value, summaryData, dataIndex, rowIndex, colIndex, store, view) {
if (value > 100)
{
summaryData.tdAttr = 'style="color: #ff0000"';
} else if (value === 100)
{
summaryData.tdAttr = 'style="color: green;"';
} else {
summaryData.tdAttr = 'style="color: yellow;"';
}
return Ext.String.format('Total: {0}%', value);
},
Note the first one would be using css classes, so you need to define the appropriate css classes in your css file :D
You can use summaryRenderer function present in grid column to show the row in specific style.
Ext.create('Ext.grid.Panel', {
width: 200,
height: 140,
renderTo: document.body,
features: [{
ftype: 'summary'
}],
store: {
model: 'TestResult',
data: [{
student: 'Student 1',
mark: 84
},{
student: 'Student 2',
mark: 72
},{
student: 'Student 3',
mark: 96
},{
student: 'Student 4',
mark: 68
}]
},
columns: [{
dataIndex: 'student',
text: 'Name',
summaryType: 'count',
summaryRenderer: function(value, summaryData, dataIndex) {
return "<font color='red'>"+value+"<font>";
}
}, {
dataIndex: 'mark',
text: 'Mark',
summaryType: 'average'
}]
});
Or we can use CSS in specific page.
<style>
.x-grid-row-summary .x-grid-cell{
background-color: #f00 !important;
font-size: x-large !important;
}
</style>