PDA

View Full Version : Grid Sorting Problem



rakesh
2 Aug 2007, 6:37 AM
Hello Community,
I am fetching data from server and displaying in Ext Grid by using JSON Reader.I would like to sort the grid now, but problem is that i have some columns which display
quantities(100 MT, 20 lb) and prices(200 USD/MT, 300 EUR/MT) along with their units and currenices but i would like to sort those columns on basis of numbers.Is there any way to do it using Ext.

fay
2 Aug 2007, 6:55 AM
If your JsonReader returns the 'quantity' and 'quantity unit' fields seperately it should be no problem to use the data store's setDefaultSort() method. Then use a custom renderer in your grid to display the fields together in one column. I've done something similar:


function renderImpellerDiameter(value, p, record){
return String.format('{0} {1}', parseFloat(record.data['Impeller']).toFixed(3), record.data['ImpellerUnit']);
};

var dsPumps = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'pumps.xml'}),
reader: new Ext.data.XmlReader({record: 'TBasicPump', id: 'PumpId'}, ['PumpName', 'Impeller', 'ImpellerUnit'])
});
dsPumps.setDefaultSort('Impeller', 'ASC');

var cmPumps = new Ext.grid.ColumnModel([
{header: "Pump Name", width: 120, dataIndex: 'PumpName'},
{header: "Imp. Dia.", width: 180, dataIndex: 'Impeller', renderer: renderImpellerDiameter}
]);

rakesh
2 Aug 2007, 9:09 PM
Thanks a ton Fay!!!