Having trouble getting help?
Contact Support
Contact Support
Get row cell index in Angular Treegrid component
27 Apr 20243 minutes to read
You can get the specific row and cell index of the Tree Grid by using rowSelected
event of the treegrid. Here, we can get the row and cell index by using aria-rowindex (get row Index from tr element) and aria-colindex (column index from td element) attribute.
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 {ButtonModule} from '@syncfusion/ej2-angular-buttons'
import { DropDownListAllModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component, OnInit, ViewChild } from '@angular/core';
import { projectData } from './datasource';
import { TreeGridComponent } from '@syncfusion/ej2-angular-treegrid';
import { RowSelectEventArgs } from '@syncfusion/ej2-angular-grids';
@Component({
imports: [
TreeGridModule,
ButtonModule,
DropDownListAllModule
],
providers: [PageService,
SortService,
FilterService],
standalone: true,
selector: 'app-container',
template: `<ejs-treegrid #treegridObj [dataSource]='data' idMapping='TaskID' parentIdMapping='parentID' [treeColumnIndex]='1' (rowSelected)='rowSelected($event)' [height]='267'>
<e-columns>
<e-column field='TaskID' headerText='Task ID' width='70' textAlign='Right'></e-column>
<e-column field='TaskName' headerText='Task Name' width='150' ></e-column>
<e-column field='StartDate' headerText='Start Date' textAlign='Right' [format]='formatOptions' width='90'></e-column>
<e-column field='EndDate' headerText='Start Date' textAlign='Right' [format]='formatOptions'width='90'></e-column>
<e-column field='Duration' headerText='Duration' width='80' textAlign='Right'></e-column>
<e-column field='Progress' headerText='Progress' width='80' textAlign='Right'></e-column>
<e-column field='Priority' headerText='Priority' width='90'></e-column>
</e-columns>
</ejs-treegrid>`,
})
export class AppComponent implements OnInit {
public data: Object[] = [];
public formatOptions?: Object;
ngOnInit(): void {
this.data = projectData;
this.formatOptions = { format: 'y/M/d', type: 'date' };
}
rowSelected(args: RowSelectEventArgs) {
alert("row index: "+ " " + (args.row as HTMLTableRowElement).getAttribute('aria-rowindex'));
alert("column index: "+ " " + ((args.target as Element).closest('td') as HTMLTableCellElement).getAttribute('aria-colindex'));
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
You can refer to our
Angular Tree Grid
feature tour page for its groundbreaking feature representations. You can also explore ourAngular Tree Grid example
to knows how to present and manipulate data.