handleDataBound(args) {
console.log("Data Bound", args);
const rows = args.result;
if (this.updateCollapse) {
this.updateCollapse = false;
if (this.rowStates) {
console.log("UPDATE COLLAPSE", this.rowStates);
Object.keys(this.rowStates).forEach(
rowId => {
if (rows) {
const row = rows.find(gridRow => gridRow.id === rowId)
const state = this.rowStates[rowId];
if (row && state) {
row['expanded'] = state === RowCollapsedState.Expanded;
}
}
}
)
}
}
onCollapsed(args) {
if (args.data && args.data.id) {
const rowId = args.data.id;
this.rowStates[rowId] = RowCollapsedState.Collapsed
// this.addCollapsedRow.emit(rowId);
}
}
onExpanded(args) {
if (args.data && args.data.id) {
const rowId = args.data.id;
this.rowStates[rowId] = RowCollapsedState.Expanded
// this.addCollapsedRow.emit(rowId);
}
}
App.Component.html
<ejs-treegrid [dataSource]="treeRows" idMapping="id" parentIdMapping="pid" #treeGrid
[enableVirtualization]="true" [height]="600(beforeDataBound)="dataBound($event)"
(expanded)="onExpanded($event)" (collapsed)="onCollapsed($event)">
<e-columns>
<e-column field="label" ></e-column>
. . .
</e-columns>
</ejs-treegrid>
App.Component.ts
export class AppTreeGridComponent implements OnInit, AfterViewInit {
@ViewChild('treeGrid') public grid: TreeGridComponent;
public state: boolean;
constructor(private rowsService: RowsService) { }
ngOnInit() : void {
}
onExpanded(args)
{
. . .
}
onCollapsed(args)
{
const rowId = args.data.id;
this.state = !args.data.expanded;
this.rowStates[rowId] = this.state;
}
dataBound(args: any)
{
const rows = args.result;
if (this.rowStates)
{
console.log("UPDATE COLLAPSE", this.rowStates);
Object.keys(this.rowStates).forEach(
rowId => {
if (rows)
{
const row = rows.find(gridRow => gridRow.id === rowId)
const state = this.rowStates[rowId];
if (row && state)
{
row['expanded'] = state === false
}
}
})
}
}
} |