Get Node Level on DataBound

2 posts, 0 answers
  1. UBALDI SI
    UBALDI SI avatar
    4 posts
    Member since:
    Jul 2013

    Posted 06 Nov Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    1405 posts

    Posted 08 Nov Link to this post

    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.
Back to Top