This is a migrated thread and some comments may be shown as answers.

how to expand the async treeview node

1 Answer 160 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
xu
Top achievements
Rank 1
xu asked on 14 Sep 2012, 01:49 AM
my treeview ::
    var opcPath = "";
    var dataSource = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "../fwp/getOPCTree.fwp?opcPath=" + opcPath,
                type: "GET",
                dataType: "json"
            }
        },
        schema: {
            model: {
                id: "opcPath",
                hasChildren: "hasChildren"
            }
        }
    });
    //初始化OPC树
    treeview = $("#opcTreeView").kendoTreeView({
        select: onOPCTreeSelect,
        dataSource: dataSource,
        dataTextField: "nodeName",
        dataSpriteCssClassField: "nodeCSS",
        dataImageUrlField: "imageUrl"
    });

the treeview is async!!!!
i can get the id "opcpath".
when the root is expand, 
but the child is not expand,
then i want to expand the child child child .....node through the id.
how  to do??

1 Answer, 1 is accepted

Sort by
0
Accepted
Nohinn
Top achievements
Rank 1
answered on 14 Sep 2012, 08:17 AM
Use the change event of the dataSource.
dataSource: {
    ...
    change: function(e) {
        if(e.items.length > 0 && e.action == "itemchange") {
             // your code to look for the new node to expand here
        }
    }
}

Then expand your root node through the uid attribute (as the treeview has it's own findByUid method).
var t = $('#TreeView').data('kendoTreeView');
t.expand(t.findByUid('UidHere'));

When it expands and is going to add the children nodes it will fire the change event, if you need to keep opening more nodes you will have to do the same within the change event (look for the node and expand it).
Tags
TreeView
Asked by
xu
Top achievements
Rank 1
Answers by
Nohinn
Top achievements
Rank 1
Share this question
or