The TreeGrid component for Angular represents a lightweight widget which represents data in a tree-like structure.
npm install -g @angular/cli ng new jqwidgets-project cd jqwidgets-project
ng add jqwidgets-ng
jQWidgets UI for Angular is distributed as jqwidgets-ng NPM package
npm install jqwidgets-ng
@import 'jqwidgets-ng/jqwidgets/styles/jqx.base.css';
"styles": [ "node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css" ]
<jqxTreeGrid [theme]="'fluent'" #treeGridReference
[width]="getWidth()" [height]="'auto'" [source]="dataAdapter" [pageable]="true" [columns]="columns" [ready]="ready">
</jqxTreeGrid>
import { Component, ViewChild } from '@angular/core';
import { jqxTreeGridModule, jqxTreeGridComponent } from 'jqwidgets-ng/jqxtreegrid';
@Component({
selector: 'app-root',
imports: [jqxTreeGridModule],
standalone: true,
templateUrl: './app.component.html'
})
export class AppComponent {
@ViewChild('treeGridReference') treeGrid: jqxTreeGridComponent;
getWidth(): any {
if (document.body.offsetWidth < 850) {
return '90%';
}
return 850;
}
source: any =
{
dataType: "csv",
dataFields: [
{ name: 'EmployeeKey', type: 'number' },
{ name: 'ParentEmployeeKey', type: 'number' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{ name: 'Title', type: 'string' },
{ name: 'HireDate', type: 'date' },
{ name: 'BirthDate', type: 'date' },
{ name: 'Phone', type: 'string' },
{ name: 'Gender', type: 'string' },
{ name: 'DepartmentName', type: 'string' }
],
hierarchy:
{
keyDataField: { name: 'EmployeeKey' },
parentDataField: { name: 'ParentEmployeeKey' }
},
id: 'EmployeeKey',
url: '../assets/employeesadv.txt'
};
dataAdapter: any = new jqx.dataAdapter(this.source);
columns: any[] =
[
{ text: 'FirstName', dataField: 'FirstName', minWidth: 100, width: 200 },
{ text: 'LastName', dataField: 'LastName', width: 200 },
{ text: 'Department Name', dataField: 'DepartmentName', width: 150 },
{ text: 'Title', dataField: 'Title', width: 300 },
{ text: 'Birth Date', dataField: 'BirthDate', cellsFormat: 'd', width: 120 },
{ text: 'Hire Date', dataField: 'HireDate', cellsFormat: 'd', width: 120 },
{ text: 'Phone', dataField: 'Phone', cellsFormat: 'd', width: 120 }
];
ready: any = () => {
this.treeGrid.expandRow(32);
};
}