Every node causes a call to _initChildren even if it doesn't have children.
If i have one root node with 1000 children (leafs w/o children) the call to _initChildren is made 1001 times. If you use load on demand the call is only done for the nodes you expand, and nodes without children can't be expanded. It is obvious that the information on wheter the node has children or not is available before the _initChildren is called. For larges datasources (~1000 nodes) this often causes the browser to halt (alerting ~A script is causing the page to run slowly..).
By changing kendo.data.js (start line 2832 in 2012.2.913) from:
load:
function
() {
var
that =
this
,
options = {};
that._initChildren();
if
(!that._loaded || that.hasChildren) {
options[that.idField ||
"id"
] = that.id;
if
(!that._loaded) {
that.children._data = undefined;
}
that.children.one(CHANGE,
function
() {
that._loaded =
true
;
})
._query(options);
}
},
To:
load:
function
() {
var
that =
this
,
options = {};
if
(that.hasChildren)
{
that._initChildren();
options[that.idField ||
"id"
] = that.id;
if
(!that._loaded) {
that.children._data = undefined;
}
that.children.one(CHANGE,
function
() {
that._loaded =
true
;
})
._query(options);
}
},
The loading time is cut by ~80% (one typical example would be from 30s to 7s) in my average trees (a lot more in the example given above).
Though I don't now it the above code change can have any unforseen consequences, or if there is a better way to accomplish a similar effect.
Would love to hear you thoughts on this.