Error when collapseall treegrid

Hi, I wanted to collapseall my treegrid but it gave me this error. I check the generated treegrid

3 Replies 1 reply marked as answer

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team June 7, 2021 01:35 PM UTC

Hi Toan,             

Thanks for your interest in Syncfusion Components. 

Query#:- Hi, I wanted to collapseall my treegrid but it gave me this error.(Cannot read property filter of undefined) 

We have checked your query and we are able to replicate the problem at our end(collapseAll with created event). TreeGrid rows has not been rendered at created event. So the reported problem occurs. To overcome this problem, we suggest to use collapseAll method in dataBound event of the TreeGrid

Refer to the code below:- 
App.Component.html 

<ejs-treegrid #treegrid [dataSource]="data" childMapping="subtasks" 
   height="350"[treeColumnIndex]="1"[allowPaging]="true" 
              [pageSettings]="pageSettings" 
              (dataBound)="dataBound($event)"> 
    <e-columns> 
 
             .    .     . 
    </e-columns> 
</ejs-treegrid> 

App.Component.ts 

export Class AppComponent { 
  Public data : Object[] = []; 
  Public pageSettings : Object; 
  @ViewChild('treegrid') 
  Public treegrid :   TreeGridComponent; 
 
  ngOnInit() void { 
    this.data = sampleData; 
    this.pageSettings = { pageSize: 10 }; 
  } 
  dataBound(args) { 
    this.treegrid.collapseAll(); 
 } 
} 



Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 



TB Toan Bui June 8, 2021 03:13 AM UTC

This makes it impossible for me to expand them. I just want to collapse them on created, then I can still expand them if needed


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team June 8, 2021 03:24 PM UTC

Hi Toan,          

Query#:- I just want to collapse them on created, then I can still expand them if needed 
 
From your query we understood that you need to Collapse the TreeGrid rows on Initial Render alone. To achieve this we suggest you to enable  CollapseAll method on initial rendering by checking condition(this.treegrid.InitialRender). 
 
Refer to the code below:- 
  public data: Object[] = []; 
    public pageSettings: Object; 
  @ViewChild('treegrid') 
    public treegrid: TreeGridComponent; 
 
  ngOnInit(): void { 
    this.data = sampleData; 
    this.pageSettings = { pageSize: 10 }; 
  } 
  dataBound(args) { 
    if (this.treegrid.initialRender) { 
      this.treegrid.collapseAll(); 
    } 
  } 
 
 
Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 


Marked as answer
Loader.
Up arrow icon