How to run TreeGrid Angular examples

Download TreeGrid examples package from http://www.treegrid.com/Download#Trial and unzip it to some directory, preserve its directories structure.

Angular examples per Angular version

TreeGrid examples package contains simple examples for Angular framework located in /ExamplesNode/Angular/.
There are always two example sets per Angular version, one creates TreeGrid statically by <treegrid> and the second one with -dynamic suffix creates TreeGrid dynamically by TreeGrid( ) function.

Install and run the Angular examples

If you have any problems running Angular examples please contact our technical support.


Optionally install and run sample NodeJS server that serves data for the Angular example from SQLLite database.

The server is needed for the most of the Angular examples to serve their data.


Using TreeGrid in Angular project



Installation

1) Copy TreeGrid distribution (/Grid)

Copy TreeGrid required files from TreeGrid examples package to the Angular project. The TreeGrid examples package can be downloaded from http://www.treegrid.com/Download#Trial

2) Add paths to static files (assets)

Modify angular.json (or .angular-cli.json in 5.x and older), add to assets array all the files and directories that will be served directly without processing them by Angular.
Note that there can be more assets sections in angular.js, e.g. for "build" and "test", modify all of them.
In Angular 5 and older the served static files must be inside /src directory or some its subdirectory!

3) Include TreeGrid script (GridE.js)

Link TreeGrid script file GridE.js to the Angular main file src/index.html into <head> section as <script src="Grid/GridE.js"></script>, the path to the GridE.js file is defined in previous point 2).
Or if your Angular project displays TreeGrid only conditionally, you can link GridED.js short script instead of GridE.js main script to download the GridE.js automatically on demand.

4) Copy TreeGrid API definition (TreeGrid.TypeScript.API.d.ts)

Copy file TreeGrid.TypeScript.API.d.ts (located in the TreeGrid examples package in /ExamplesNode/ directory) to the /src directory.
This file contains TypeScript declaration of all TreeGrid API methods, properties and events.
If you use isolatedModules, import the TreeGrid.TypeScript.API.d.ts to all files where the TreeGrid API is used.

5) Copy and link TreeGrid component definition (TreeGrid.component.ts)

It is required only if TreeGrid is created statically by <treegrid> tag and not dynamically by TreeGrid() function.
It is possible to modify this file e.g. to assign specific TreeGrid API events.


Create TreeGrid grid / Gantt / sheet

6) Create TreeGrid statically by HTML tag (<treegrid>)

Create TreeGrid statically somewhere in your page by adding <treegrid> tag to some html file.
Include <treegrid> tag in some <div> element that will be used as TreeGrid container (called MainTag).
For example add such code <div style="height:500px;"><treegrid Debug='check' Layout_Url="Layouts/StaticDef.js" Data_Url="Layouts/StaticData.js"></treegrid></div>.
For more information about <treegrid> tag see Creating TreeGrid.

7) Create TreeGrid dynamically by script (TreeGrid(...))

Or create TreeGrid dynamically from TypeScript by TreeGrid( ) function. For this way the point 5) is not required.
For example: var grid = TreeGrid({Debug:'check', Layout: { Url:"Layouts/StaticDef.js" }, Data: { Url:"Layouts/StaticData.js" } },"MyTag");, where MyTag is an id of <div> tag where TreeGrid will be created (it will be TreeGrid MainTag).
For more information about TreeGrid( ) function see Creating TreeGrid.

Existing grid can be deleted by grid.Dispose( ) method. For more information see Deleting TreeGrid.
To reload grid with new content use grid.ReloadBody( ) method, to recreate grid completely from new layout and data use grid.Reload( ) method. For more information see Reloading TreeGrid.
To access existing grid on page by API link the TreeGrid with Angular component in point 8) or use global Grids object as Grids[grid_id] or for the only grid on page use Grids[0], for example Grids[0].Reload();.
For more information see Accessing TreeGrid by API.

8) Link created TreeGrid with Angular component (for API)

The simplest way is to assign a reference to Angular component in TreeGrid object and assign a reference to TreeGrid object in Angular component.


Create TreeGrid data (structure and content)

9) TreeGrid data formats (JSON / XML)

10) Defining TreeGrid layout (columns and configuration)

TreeGrid layout defines the grid / Gantt structure: configuration, columns (types, formats, widths, ...), toolbars, control rows, Gantt definition, etc. Simply it contains the whole TreeGrid definition except body rows and their cells. See Layout format and JSON format.
TreeGrid layout is usually static JSON or XML file located in assets (see point 2)).
But TreeGrid layout can be also dynamically created on server or by API or merged to TreeGrid data.
The layout definition is assigned in Layout object in TreeGrid() method (e.g. TreeGrid({Layout:{Url:'test.json'},...},...)) or with Layout_ prefix in <treegrid> tag (e.g. <treegrid Layout_Url='test.json' ... >).
For more information about the TreeGrid layouts see especially the Tutorial examples in this package that describe individual features and how defined and use them.

11) Creating TreeGrid data (rows and cells)

TreeGrid data defines the grid data rows and their cells with values. see Data format and JSON format.
TreeGrid data is usually created dynamically on server side from database or any other data source.
But TreeGrid data can be also static JSON / XML file or it can be generated dynamically by API.
The data definition is assigned in Data object in TreeGrid() method (e.g. TreeGrid({Data:{Url:'testdata.json'},...},...)) or with Data_ prefix in <treegrid> tag (e.g. <treegrid Data_Url='testdata.json' ... >).

12) TreeGrid data communication (AJAX / REST)

There are three usual ways of passing data to TreeGrid.


TreeGrid events and API

13) Catch TreeGrid XML/JSON events (Actions in data)

The XML/JSON event handlers are defined in TreeGrid Defaults.xml (located in /Grid directory), in layout XML/JSON file or data or in another input XML/JSON data.
The XML/JSON events are mostly mouse and key events like OnClick or OnMouseMove. There are also a few special events like OnChange.
The handlers are defined by On... attribute in Actions tag for the whole grid or by On... attribute assigned to particular column, default column, row, default row, row cell, default row cell.
The handlers are defined as JavaScript code in string. For example Actions: { ... OnClick:"alert('Clicked cell '+Row.id+','+Col);return 1;" ... } or Body:[[{... Col1OnClick:"alert('Clicked cell '+Row.id+','+Col);return 1;" ...},...]]
The Angular component (linked in point 8)) can be accessed in the handler code by Grid.Component, for example Actions: { ... OnClick:"Grid.Component.MyProcessClick(Row,Col)" ... }
The handler should return 1 to cancel event propagation or 0 to continue propagation and run next event handlers.
For more information see TreeGrid mouse events and TreeGrid key events.

14) Catch TreeGrid API events (in script)

TreeGrid API event handlers are JavaScript callbacks, they are defined as standard JavaScript / TypeScript functions that are called from TreeGrid code when the API event happens.
The API events can be used to run some code after TreeGrid is loaded, ready or rendered or some action is started or finished like data communication, editing, sorting, filtering, mouse actions like click, etc.
The event handlers can be assigned before any TreeGrid is created, e.g. in constructor of Angular component that uses TreeGrid.
For example: export class AppComponent { ... constructor(...){ ... Grids.OnReady = function(G){ alert(G.id+" grid is ready to render"); } ... } ...
For more information about assigning API events see TreeGrid API events.

15) Using TreeGrid API (API methods)

The most of TreeGrid API methods are methods of (TGrid) grid object. The grid object can be got by this.Grid if called in the Angular component linked with created TreeGrid as described in point 8).
Or grid object can be got by global Grids object as Grids[grid_id] or for the only grid on page use Grids[0], for example Grids[0].Reload();. For more information see Accessing TreeGrid by API.
Many TreeGrid methods require (TRow) row object. The row object can be got by its id by GetRowById API method or by iterating rows, see Row iteration.
The column are passed to TreeGrid methods by their names as strings. The columns can be also iterated see Column iteration.