Reputation: 19165
I know I can format an ExtJs grid's column by using Ext.Util.Format class. I want to know how can I apply following format types:
Thank you
Upvotes: 1
Views: 6236
Reputation:
I would have liked to have some more details :
Anyway, I can give it a try (you should read the doc first).
Renderer 1 :
renderer: function (value) {
return value + '%';
}
Renderer 2 :
renderer: function (value) {
return value < 0
? '<span style="color:red">(' + Math.abs(value) + ')</span>'
: value;
}
Frankenstein's monster :
renderer: function (value) {
return value < 0
? '<span style="color:red">(' + Math.abs(value) + '%)</span>'
: value + '%';
}
Upvotes: 2
Reputation: 3263
Yes, you can achieve through renderer
concept, please refer below sample for your queries.
{
text : 'Number (Percentage)',
width : 80,
sortable : true,
renderer : function(val) {
if (val > 0) {
return '<span style="color:green;">' + val + '</span>';
} else if (val < 0) {
return '<span style="color:red;">' + val + '</span>';
}
return val+"%";
},
dataIndex: 'numberChange' // place your dataindex binding here
}
Thanks, Hope this will help you...
Upvotes: 1
Reputation: 3114
You could easily implement a renderer for the columns, and transform the results however you'd like. All you have to do is return the transformed string from the renderer; plus, you have access to the full Ext.data.Record
for the grid row (as well as the store, for that matter), so you can also easily do custom renderings based on other data within the record, if needed.
Upvotes: 0