I figured out how to do this and it did make a big difference in performance for my app's treegrid. Here is what I did:
Extend the 'autoSizeColumn' method for the treegrid:
var origTreegrid_autoSizeColumn = $.fn.datagrid.methods['autoSizeColumn'];
$.extend($.fn.treegrid.methods, {
autoSizeColumn: function(jq, field) {
$.each(jq, function() {
var opts = $(this).treegrid('options');
if (!opts.skipAutoSizeColumns) {
var tg_jq = $(this);
if (field) origTreegrid_autoSizeColumn(tg_jq, field);
else origTreegrid_autoSizeColumn(tg_jq);
}
});
}
});
Then when I setup my treegrid, set skipAutoSizeColumns to 'false' and install handlers to track the expand/collapse operations:
$('#tg').treegrid({
fit: true,
url: 'getMyData',
skipAutoSizeColumns: false,
onBeforeExpand: function() {
$(this).treegrid('options').skipAutoSizeColumns = true;
},
onBeforeCollapse: function() {
$(this).treegrid('options').skipAutoSizeColumns = true;
},
onExpand: function() {
$(this).treegrid('options').skipAutoSizeColumns = false;
},
onCollapse: function() {
$(this).treegrid('options').skipAutoSizeColumns = false;
}
});
The result is the 'autoSizeColumns' method is called normally when the grid data is loaded to get the column sizing initialized properly - but then expanding/collapsing nodes is *much* faster and more responsive -- even if the data needs to be fetched from the server to fill in the children nodes.