If use TreeRow.hasChildren property and TreeView.onExpanding event, you can configure the data set which will be displayed in the tree view by loading the child rows when the user clicks expander to expand the row during the run time.
// Set hasChildren as true after loading only the rows of the top level.
ds.setRows(rows);
tree.visitAllRows(function (row) {
row.setHasChildren(true);
});
// Load the child rows of the row which hasChildren is true.
tree.onExpanding = function (tree, row) {
if (row.hasChildren()) {
for (var i = 1; i <= 3; i++) {
var dataRow = row.dataRow();
var vals = dataRow.getObject();
vals['loan_number'] += '_' + i;
vals['country'] += '_2';
ds.addRow(dataRow, vals);
// Load the child rows to level 2.
if (row.level() == 1) {
row.getChild(i - 1).setHasChildren(true);
}
}
}
};