PDA

View Full Version : Grid column with file sizes - rendering and sorting



alexander.urban
17 Apr 2014, 5:49 AM
I have a grid with file sizes, which are set in the store as numbers (in bytes). The column can be sorted. I now want to make the filesize readable (e.g. 52174 displayed as 51 KB) without losing sortability. How would I go for that?

scottmartin
17 Apr 2014, 6:05 AM
You should be able setup a column renderer to change the display value, but sort should remain on the value



Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'change'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "change":1000 },
{ 'name': 'Bart', "email":"bart@simpsons.com", "change":10000 },
{ 'name': 'Homer', "email":"home@simpsons.com", "change":2000 },
{ 'name': 'Marge', "email":"marge@simpsons.com", "change":25000 }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email' },
{ header: 'Change', dataIndex: 'change',
renderer: function(value) {
if (value === 25000) {
value = '25K';
} else if (value === 10000) {
value = '10K';
}

return value;

}
}
],
height: 200,
width: 400,
renderTo: Ext.getBody()


});

});