| layout | post |
|---|---|
| title | Getting-Started with Angular TreeGrid | Syncfusion |
| description | Learn here about getting started with the Syncfusion Angular TreeGrid control, its elements, and more |
| platform | Angular |
| control | TreeGrid |
| documentation | ug |
This section helps to understand the getting started of the Angular TreeGrid with the step-by-step instructions.
To quick start with Syncfusion JavaScript Angular components run the below commands to clone the repository for SystemJS starter and installing required dependency packages.
{% highlight javascript %}
git clone https://github.com/syncfusion/angular2-seeds/ -b systemjs
cd angular2-seeds
npm install {% endhighlight %}
The below steps describes to add component with above cloned seed application.
- Copy required Syncfusion Angular source component(s) from the below build location and add it in
src/ejfolder (For ex., consider theTreeGridcomponent).
{% highlight javascript %} (Installed Location)\Syncfusion\Essential Studio{{ site.releaseversion }}\JavaScript\assets-src\angular2\ {% endhighlight %}
N> core.ts file is mandatory for all Syncfusion JavaScript Angular components. The repository having the source file from Essential Studio for JavaScript v{{ site.releaseversion }}.
-
Create
TreeGridfolder insidesrcfolder. -
Create
TreeGrid.component.htmlview file insidesrc/TreeGridfolder and render ejTreeGrid Angular component using the below code example.
{% highlight html %}
<ej-treegrid id="TreeGridControl" [dataSource]="treeGridData" childMapping="subtasks" [treeColumnIndex]=treeColumnIndex sizeSettings.height="400px" sizeSettings.width="100%">
{% endhighlight %}
- Create
TreeGrid.component.tsmodel file inside the foldersrc/TreeGridand create sample component using the below code example.
{% highlight javascript %}
import { Component } from '@angular/core';
@Component({ selector: 'ej-app', templateUrl: 'app/components/treeGrid/treeGrid.component.html', styleUrls: ['app/components/treeGrid/treeGrid.component.css'], })
export class DefaultComponent {
this.treeGridData = [{
taskID: 1,
taskName: "Planning",
startDate: "02/03/2014",
endDate: "02/07/2014",
progress: 100,
duration: 5,
subtasks: [
{ taskID: 2, taskName: "Plan timeline", startDate: "02/03/2014", endDate: "02/07/2014", duration: 5, progress: 100 },
{ taskID: 3, taskName: "Plan budget", startDate: "02/03/2014", endDate: "02/07/2014", duration: 5 },
{ taskID: 4, taskName: "Allocate resources", startDate: "02/03/2014", endDate: "02/07/2014", duration: 5, progress: 100 },
{ taskID: 5, taskName: "Planning complete", startDate: "02/07/2014", endDate: "02/07/2014", duration: 0, progress: 0 }
]
}]
public treeColumnIndex = 1; }
{% endhighlight %}
Before adding router configuration for above created ejTreeGrid component, we recommend you to go through the Angular Routing configuration to get the deeper knowledge about Angular routing.
- Now, we are going to configure the route navigation link for created TreeGrid sample in
src/app.component.htmlfile.
{% highlight html %}
-
. . . .
- TreeGrid
- Import the ejTreeGrid sample component and define the route in
src/app.routes.tsfile.
{% highlight javascript %} import { Routes } from '@angular/router'; . . . . import { TreeGridComponent } from './treeGrid/treeGrid.component';
export const rootRouterConfig: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, . . . . { path: 'treeGrid', component: TreeGridComponent } ]; {% endhighlight %}
- Import and declare the Syncfusion source component and ejTreeGrid sample component into
app.module.tslike the below code snippet.
{% highlight javascript %}
import { NgModule, enableProdMode, ErrorHandler } from '@angular/core'; . . . . . import { EJ_TREEGRID_COMPONENTS } from './ej/treeGrid.component'; import { TreeGridComponent } from './treeGrid/treeGrid.component';
import { rootRouterConfig } from './app.routes'; . . . . @NgModule({ imports: [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(rootRouterConfig, { useHash: true })], declarations: [. . . . , EJ_TREEGRID_COMPONENTS,TreeGridComponent], bootstrap: [AppComponent] }) export class AppModule { } {% endhighlight %}
A TreeGrid Control is created as shown in the following screen shot.
The TreeGrid control has sorting functionality, to arrange the data in ascending or descending order based on a particular column.
Enable the multicolumn sorting in TreeGrid by setting allowMultiSorting as true. You can sort multiple columns in TreeGrid, by selecting the desired column header while holding the Ctrl key.
{% highlight html %}
<ej-treegrid id="TreeGridControl" [allowSorting]="true" [allowMultiSorting]="true">
{% endhighlight %}
You can enable Editing in TreeGrid by using the editSettings property as follows.
{% highlight html %}
<ej-treegrid id="TreeGridControl" [editSettings]="editSettings"
{% endhighlight %}
{% highlight javascript %}
import { Component } from '@angular/core';
@Component({ selector: 'ej-app', templateUrl: 'app/components/treeGrid/treeGrid.component.html', styleUrls: ['app/components/treeGrid/treeGrid.component.css'], })
export class DefaultComponent { this.editSettings = { allowAdding: true, allowEditing: true, allowDeleting: true, editMode: 'cellEditing', rowPosition: 'belowSelectedRow' }; }
{% endhighlight %}
And also, the following editors are provided for editing support in TreeGrid control.
- string
- boolean
- numeric
- dropdown
- datepicker
- dateTimePicker
You can set the editor type for a particular column as follows.
{% highlight html %}
{% endhighlight %}
The output of the DateTimePicker editor in TreeGrid control is as follows.
- To run the application, execute below command.
{% highlight javascript %} npm start {% endhighlight %}
- Browse to http://localhost:3000 to see the application. And navigate to TreeGrid tab. The component is rendered as like the below screenshot. You can make changes in the code found under src folder and the browser should auto-refresh itself while you save files.


