Flex grid Tree View - How to fetch root node by its children

Posted by: lk_richard on 29 April 2020, 11:11 pm EST

    • Post Options:
    • Link

    Posted 29 April 2020, 11:11 pm EST

    Hi Team,

    For a grid tree like https://www.grapecity.com/wijmo/demos/Grid/TreeGrid/ChildItems/angular

    how can I get the root node and the chain by clicking any of the children nodes?

    For instance, if clicking “Billy”, I need Albert and Benjamin.

    Thanks in advance.

  • Posted 30 April 2020, 1:28 am EST

    Hi Richard,

    In the selectionChanged event of the FlexGrid, you can iterate over the rows above the currently selected row and if the level of the above row is less than the current row, then it is the parent:

    this.familyGrid.selectionChanged.addHandler((s, e) => {
                var item = s.rows[e.row].dataItem;
                var chains = [item];
                var lvl = s.rows[e.row].level;
                for(let i = e.row - 1; i >= 0; i--) {
                    var curRow = s.rows[i];
                    if(curRow.level < lvl) {
                        var curItem = curRow.dataItem;
                        chains.splice(0, 0, curItem);
                        lvl = curRow.level;
                    }
                }
                console.log(chains);
            });
    

    Also, if the case of Billy, the chain will be Benjamin → Bridget → Billy.

    Regards,

    Ashwin

  • Posted 30 April 2020, 3:54 am EST

    Thanks so much, Ashwin. But I could not find the Level property.

    Codes is showing No Level property in Type Row.

  • Posted 30 April 2020, 4:11 am EST

    Hi Richard,

    Just cast the object returned by the grid.rows array to an object of GroupRow:

    var lvl = (s.rows[e.row] as wjcGrid.GroupRow).level;
    

    This error occurs because the rows array returns an instance of Row object which does not contain the level property.

    ~regards

  • Posted 30 April 2020, 5:05 am EST

    Thanks a lot, Ashwin! You are so helpful and responsive!

  • Posted 30 April 2020, 5:25 am EST

    Thank you, Richard. Happy to help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels