Select treegrid rows based on certain condition in Angular Treegrid component

21 Sep 20224 minutes to read

You can select the specific row in the Tree Grid based on a certain condition by using the selectRows method in the dataBound event of Tree Grid.

In the below demo, we have selected the Tree Grid rows only when Duration column value greater than 4.

import { Component, OnInit, ViewChild } from '@angular/core';
import { projectData } from './datasource';
import { TreeGridComponent,SelectionSettingsModel  } from '@syncfusion/ej2-angular-treegrid';
import { RowDataBoundEventArgs } from '@syncfusion/ej2-angular-grids';
import { getValue } from '@syncfusion/ej2-base';

    selector: 'app-container',
    template: `<ejs-treegrid #treegridObj [dataSource]='data' idMapping='TaskID' parentIdMapping='parentID'
    [treeColumnIndex]='1' [height]='269' allowPaging='true' (rowDataBound)='rowDataBound($event)'
    (dataBound)='dataBound($event)' [selectionSettings]='selectionOptions'>
            <e-column field='TaskID' headerText='Task ID' width='70' textAlign='Right'></e-column>
            <e-column field='TaskName' headerText='Task Name' width='100' ></e-column>
            <e-column field='StartDate' headerText='Start Date' textAlign='Right' [format]='formatOptions' editType='datepickeredit'  width='100' ></e-column>
            <e-column field='EndDate' headerText='End Date' textAlign='Right' [format]='formatOptions' editType='datepickeredit'  width='100'></e-column>
            <e-column field='Duration' headerText='Duration' width='90' textAlign='Right'></e-column>
            <e-column field='Priority' headerText='Priority' width='90'></e-column>
export class AppComponent implements OnInit {

    public data: Object[] = [];
    public formatOptions: Object;
    public selectionOptions: SelectionSettingsModel;
    public selIndex: number[] = [];
    public treegridObj: TreeGridComponent;

    ngOnInit(): void { = projectData;
        this.formatOptions = { format: 'y/M/d', type: 'date' };
        this.selectionOptions = { type: 'Multiple' };
    rowDataBound(args: RowDataBoundEventArgs) {
    if (getValue('Duration', as object) > 4) {
      this.selIndex.push(parseInt((args.row as HTMLTableRowElement)
        .getAttribute('aria-rowindex') as string, 0));
    dataBound() {
      if (this.treegridObj && this.selIndex.length) {
        this.selIndex = [];
import { NgModule,ViewChild } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { TreeGridModule } from '@syncfusion/ej2-angular-treegrid';
import { PageService, SortService, FilterService } from '@syncfusion/ej2-angular-treegrid';
import { AppComponent } from './app.component';
import {ButtonModule} from '@syncfusion/ej2-angular-buttons';
import { DropDownListAllModule } from '@syncfusion/ej2-angular-dropdowns';

 * Module
    imports: [
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [PageService,
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';


You can refer to our Angular Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our Angular Tree Grid example to knows how to present and manipulate data.