How to run TreeGrid Ember examples
TreeGrid examples package contains simple examples for Ember framework located in
/ExamplesNode/Ember/.
There are two example sets created by
ember new, one normal with
JavaScript and one with
TypeScript.
Install and run Ember examples created by ember new with JavaScript or TypeScript
-
Go to directory /ExamplesNode/Ember/JavaScript/ or /ExamplesNode/Ember/TypeScript/
-
Run here command
npm install to install the node modules and wait until they are installed.
-
Next run
npm start to serve the example and wait until it is compiled (shows message in console: Build successful).
-
Finally navigate your browser to http://localhost:4200/ to run the examples.
If you have any problems running Ember examples please contact our technical support.
Optionally install and run sample NodeJS server that serves data for the Ember examples from SQLLite database.
The server is needed for the most of the Ember examples to serve their data.
-
Go to directory /ExamplesNode/Server/.
-
Run here command
npm install to install the node modules and wait until they are installed.
-
Next run
npm start to start the NodeJS server. The server serves at http://localhost:8000/.
Using TreeGrid in Ember project
Installation
1) Copy TreeGrid distribution (/Grid)
Copy TreeGrid required files from TreeGrid examples package to the Ember project.
The TreeGrid examples package can be downloaded from
http://www.treegrid.com/Download#Trial
-
Copy the whole /Grid directory, including all subdirectories, from TreeGrid package to your Ember project to the public directory.
-
Optionally copy the whole /GridSrc directory, including all subdirectories, from TreeGrid package to your Ember project to the public directory.
If you plan to modify TreeGrid css files and want to link the source css files to TreeGrid for simpler debugging.
-
Optionally if you purchased the debug sources, copy the whole TreeGrid debug sources package, including all subdirectories, to your Ember project to the public directory.
If you want to include the TreeGrid plain sources instead of compiled GridE.js file for easy debugging.
Remember, the TreeGrid source files must not be accessible outside your company!.
2) Include TreeGrid script (GridE.js)
Link TreeGrid script file
GridE.js to the Ember main html file, e.g. into
index.html, into <head> section as
<script src="Grid/GridE.js"></script>, use correct path to GridE.js file.
Or if your Ember 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.
Or you can link TreeGrid
GridE.js /
GridED.js to the
templates/application.hbs or another template file if used only here.
3) If you use TypeScript copy TreeGrid TypeScript API definition (TreeGrid.TypeScript.API.d.ts)
Copy file
TreeGrid.TypeScript.API.d.ts (located in the TreeGrid examples package in
/ExamplesNode/Ember/ directory) to the
/types directory.
This file contains TypeScript declaration of all TreeGrid API methods, properties and events.
Create TreeGrid grid / Gantt / sheet
4) Create TreeGrid statically by HTML tag (<treegrid> / <bdo>)
Create TreeGrid statically somewhere in your page by adding
<treegrid> tag to some html file or in Ember template hbs.
-
Include <treegrid> tag in some <div> element that will be used as TreeGrid container (called MainTag). It can be included directly in html code in page or in html code in Ember template hbs.
For example add such code <div style="height:500px;"><treegrid debug='check' layout_url="static/Layouts/StaticDef.js" data_url="static/Layouts/StaticData.js"></treegrid></div>.
-
If the Ember component is not rendered on page start, call StartTreeGrid() on the showing the component to process the created <treegrid> tags.
For more information about <treegrid> tag see
Creating TreeGrid.
5) Create TreeGrid dynamically by script (TreeGrid(...))
Or create TreeGrid dynamically from JavaScript or TypeScript by
TreeGrid( ) function.
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 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.
Create TreeGrid data (structure and content)
7) TreeGrid data formats (JSON / XML)
- Download data format
TreeGrid creates the grid from data in XML or JSON format. This format is proprietary for TreeGrid. The XML/JSON data contains all required definitions: configuration, columns, rows, cells, values, etc.
You need to create this XML/JSON data and pass it to TreeGrid. How this XML/JSON data is created depends fully on you. It can be created statically in some file or dynamically by some server or client script.
In this package there is NodeJS server with sample JavaScript code in Server/index.js that creates the JSON data for TreeGrid from SQLLite database or serves static file.
For more information about the TreeGrid XML/JSON data format for download see Layout format and Data format.
The documentation is for XML, the JSON format has the same tags, just different structure, see JSON format
- Upload data format
TreeGrid uploads the changes to server in XML or JSON format, similar to download format. See documentation Upload format
TreeGrid can upload only changes (added/deleted/moved/changed rows and their cells) or the whole data (all rows or even all data), it is controlled Upload_Type.
The server should parse this uploaded data and save it to its data source (database, file, etc.). This server side code is created you.
In this package there is NodeJS server with sample JavaScript code in Server/index.js that parses uploaded TreeGrid JSON data and saves the changes to SQLLite database or to static file.
8) 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, usually located in
/public or similar directory accessible directly for browser.
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.
9) 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' ... >).
10) TreeGrid data communication (AJAX / REST)
There are three usual ways of passing data to TreeGrid.
- Built-in AJAX communication
By default TreeGrid loads its data from server and uploads changes back to server by built-in AJAX.
You just specify the urls where to download and upload and their parameters and TreeGrid communicates directly with server.
For example <treegrid Layout_Url='Layouts/TableDef.js' Data_Url='http://localhost:8000/get?table=TableData&idcol=ID' Upload_Url='http://localhost:8000/set?table=TableData&idcol=ID' Upload_Format='JSON' Upload_Data='Data'>
or TreeGrid({ Layout:{Url:'Layouts/TableDef.js'}, Data:{Url:'http://localhost:8000/get?table=TableData&idcol=ID'}, Upload:{Url:'http://localhost:8000/set?table=TableData&idcol=ID', Format:'JSON', Data:'Data'},"MyTag");
For more information about the default AJAX communication see AJAX communication.
- Custom communication
For custom communication (AJAX or another type) define the TreeGrid data sources in the same way as in the previous point a.
And define API event OnCustomAjax. In this event you get all the required information for the communication. Start the custom communication and return true. And after the communication finished call the provided callback function with the result.
For example Grids.OnCustomAjax = function(G,IO,data,func){ MyAjax(IO.Url,data,function(result){ if(result<0) func(result,"Error"); else func(0,result); }); return true; }
For more information see OnCustomAjax.
- Direct data
It is possible to create TreeGrid from already loaded or created data.
Pass the data to Data parameter as string or JSON object or to Script parameter as global JavaScript variable name.
For example you can define MyObject = { MyData: {Cols:[{Name:'A'},{Name:'B'}]} };
and TreeGrid({Layout:{Script:"MyObject.MyData"},Data:{Data:{Body:[[{id:1,A:10,B:20},{id:2,A:20,B:40}]]}}},"MyTag");
or <treegrid Layout_Script:"MyObject.MyData" Data_Data="{Body:[[{id:1,A:10,B:20},{id:2,A:20,B:40}]]}">
For more information see Directly included data and Data from JavaScript.
TreeGrid events and API
11) 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 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.
12) 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.
For example:
... created: function () { ... Grids.OnReady = function(G){ alert(G.id+" grid is ready to render"); } ... }, ...
For more information about assigning API events see
TreeGrid API events.
13) Using TreeGrid API (API methods)
The most of TreeGrid API methods are methods of (TGrid) grid object.
The 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.