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

Get Node Level on DataBound

1 Answer 409 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
UBALDI SI
Top achievements
Rank 1
UBALDI SI asked on 06 Nov 2017, 11:41 AM

Hello,

I want to hide the CreateChild command ont he third level of my nodes.
So if wonder if a way to get the node level of an element exists on databound event ?

Or maybe ther is a better way to accomplish it ?

I started the databound event like this:

function dataBound(treeview) {
    var node;
    var nodes = treeview.sender.dataSource.view();
 
    for (var i = 0; i < nodes.length; i++) {
        node = nodes[i];
    }
}

I don't want use the hasChildren attribut beacause in my model sometimes element at level 2 doesn't have children.    

Thank you in advance

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 08 Nov 2017, 07:25 AM
Hello, Jeremy,

The desired result can be achieved by checking if the item has a parentId and then checking if that parentId has a parentId as well. This will hide the buttons for all levels under the 3rd. If it has to be only for the third the logic should add a check to hide the button if the last item does not have a parentId(it is the first level node):

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-get

https://docs.telerik.com/kendo-ui/api/javascript/ui/treelist#methods-itemFor

I made an example demonstrating this:

http://dojo.telerik.com/URaHO

I hope this will help to achieve the desired result.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeList
Asked by
UBALDI SI
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or