PDA

View Full Version : dynamic grid column creation performance?



seno
30 Nov 2006, 7:29 AM
sorry for my pool english :(

i need chang grid column and data models dynamically
code below, it works.

but first execute time is 1636ms,
second is 1845ms,
third is 2103ms,
....
10 is 4322ms

any hints?


var getQuestionScoreCallback = function(resp){
eval(resp.responseText);

stopwatch.init();
stopwatch.start();

scoreGrid.container.update('');
scoreGrid.colModel.purgeListeners();
scoreGrid.colModel.config = json.headers;
var schema = {
tagName: 'item',
id: 'use_index',
fields: json.items
};
var dataModel = new YAHOO.ext.grid.XMLDataModel(schema);
scoreGrid.dataModel = dataModel;


//remove column resize splitbar div
for(var i = 0; i < scoreGrid.getView().columnSplits.length; i++) {
getEl(scoreGrid.getView().columnSplits[i].id).remove();
}
scoreGrid.getView().columnSplits = [];


scoreGrid.getView().indexMap = scoreGrid.getView().buildIndexMap();
scoreGrid.getView().render();
scoreGrid.getColumnModel().totalWidth = undefined;


var xml = loadXML(json.xml);
scoreGrid.getDataModel().loadData(xml);


stopwatch.stop();
alert("time consumed : " + stopwatch.getTime());

hideLoading();
}

jack.slocum
30 Nov 2006, 8:34 AM
To be honest, I'm not sure why it would be getting slower. I do have a couple of notes for you though:

grid.setDataModel(newDataModel); will unplug the event handlers for the old data model. Which will probably free up resources.

Set 'resizable' to false or 'fixed' to true on your columns to skip the creation of the splitbar (you will still get the splitter separators though).

Try it with those two changes and see if it improves performance at all.