Toggle columns in treegrid

Hi,

I want to toogle columns in the treegrid component.

So I create a function to do that : 

    private toggleColumns(cols: TreeGridCol[]) {
        const colsToHide = cols.filter(c => c.checked === false);
        const colsToShow = cols.filter(c => c.checked === true);

        if (this.treeGridObj) {
            this.treeGridObj.grid.hideColumns(
                colsToHide.map(v => v.field),
                'field'
            );
            this.treeGridObj.grid.showColumns(
                colsToShow.map(v => v.field),
                'field'
            );
        }
    }


colsToHide and colsToShow are lists defined by an other function.

For example
colsToHide: []
colsToShow: ["name", "site", "type"]


The function  toggleColumns is cast when  colsToHide or  colsToShow changed.

But in the console I get this error : 

core.js:6498 ERROR TypeError: Cannot read properties of undefined (reading 'hide')

    at Grid.hideColumns (ej2-grids.es2015.js:15878:24)


Any idea ? Thanks or your help !


2 Replies

SS Sébastien Sivignon May 11, 2022 01:44 PM UTC

I found the solution.
It seems that I tried to hide the columns before the Tree grid was rendered...

Sorry for bothering you !



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team May 12, 2022 05:08 AM UTC

Hi CYBLEX,


Thanks for your update. Please get back to us if you need any further assistance on it. We are happy to assist you.


Regards,

Farveen sulthana T


Loader.
Up arrow icon