SMART datagrid v.1 > Examples

Back  Forward

Lazy Load Tree Data  Example
no-lite

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. 

Tree - 1
data rows
Code -1
    // 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);
                }
            }
        }
    };

View Source JSP 

See Also
TreeRow.hasChildren
TreeView.onExpanding
Tree Overview
TreeDataSet.addRow
TreeRow.getChild
Examples
Load Tree Data
Tree Data Set
Hello Tree