PDA

View Full Version : Grid performance tips



tuler
25 Sep 2007, 7:16 AM
Hi,

I need to update the contents of a grid as fast as possible.
My first try was a tradicional approach, updating the underlying record.


function onMessage(message) {
var record = ds.getById(message.data.id);
var copy = record.copy();
var values = message.data;
record.set('price', values[0]);
record.set('open', values[1]);
record.set('close', values[2]);
record.set('high', values[3]);
record.set('low', values[4]);
record.set('quantity', values[5]);
record.set('volume', values[6]);
record.commit();
}

but this is veeery slow...
I have some profile results if you are interested.
Basically camelFn and the GridView are killing the performance.

So I took another approach, just update the grid cell contents, like this:


function onMessage(message) {
var record = {};
record['price'] = values[0];
record['open'] = values[1];
record['close'] = values[2];
record['high'] = values[3];
record['low'] = values[4];
record['quantity'] = values[5];
record['volume'] = values[6];

var index = ds.indexOfId(symbol);
var view = grid.getView();
var cm = grid.getColumnModel();
(... loop through columns ... for each column)
var cell = view.getCell(index, i);
var el = Ext.get(cell);
var cellText = el.child('.x-grid-cell-text', true);
cellText.innerHTML = data;
}

This is way faster...
But... The underlying dataset is not updated.
So when I do anything with the grid, like moving a column the displayed "data" is lost (actually the underlying data was never updated).

Any tips to make the appropriate approach faster?
Thanks,
Danilo

evant
25 Sep 2007, 1:19 PM
Because the data for a record is stored in inside a variable in the record, your code should look something like this:



record.data.price = 1; //record.data.price is equivalent to record.data['price'], but a whole lot quicker.