TreeGrid Node Server
This Node Server serves and accepts data in TreeGrid JSON format and loads and saves the data in SQLite3 database or in static file. It can also generate PDF from TreeGrid.
The file
Index.js can be used as framework for application serving files for TreeGrid.
1) Install and run the Node Server
-
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/.
If you have any problems running the Node server please contact our technical support.
2) Test the NodeJS server with TreeGrid
3) Use the Node Server
By default the server serves at
http://localhost:8000/, the host and port can be changed in beginning of
Index.js file.
The server provides
five functions:
- get (http://localhost:8000/get?table=REQUIRED&idcol=id&parentcol=&defcol=) - Returns data from given table in JSON format.
- set (http://localhost:8000/set?table=REQUIRED&idcol=id&parentcol=&defcol=&autoid=) with changes in JSON in POST Data attribute - Saves posted changes to given table.
- getfile (http://localhost:8000/getfile?file=REQUIRED) - Returns data from given file without any modifications
- setfile (http://localhost:8000/setfile?file=REQUIRED) - Saves posted data (in POST Data attribute) to given file without any modifications.
- getpdf (http://localhost:8000/getpdf?layout=url&data=url) - Converts TreeGrid data in POST Data to PDF
function parameters:
- Parameter idcol can be set to the primary key column name, if the primary key column in table is not named 'id'
- Parameter parentcol should be set to column name where row Parent attribute is stored, the Parent contains the id of the parent row
- Parameter defcol should be set to column name where row Def attribute is saved, if the rows can have different Def
- Parameter autoid should be set to 1 if the table generates the record ids automatically
- Parameters layout and data in getpdf can be set to url where to load TreeGrid layout and data
4) Server files description
- Index.js - main and only JavaScript script that provides the server functionality.
It loads data from and saves data to SQLLite3 database in file SQLite.db. It uses module better-sqlite3 module for communication with SQLLite3 database.
function get it runs SQL SELECT to select all data from given table and converts the result set to the TreeGrid JSON format.
function set parses provide TreeGrid JSON data and generates SQL commands INSERT, DELETE and UPDATE to save the changes to the database.
The file provides also function getfile and setfile to read data from and write data to given file without any modifications.
- SQLite.db - Sample SQLLite3 with tables for TreeGrid examples for Angular, React and other frameworks.
It contains five table for five examples: TableData, TreeData, GanttBasic, GanttTree and Run.
- SQLite.sql - SQL script that can create and fill the sample tables in SQL database.
Use it to create the sample tables in other SQL database like MySQL or MSSQL server.
- SheetData.js - source JSON file for Sheet example to be served and saved as is.
- ExportPDF.html - Support html file for PDF export. It shows printed TreeGrid according to parameters in URL. It is run on server in Chrome headless.
- TreeGridNodeServer.html - this documentation
- package.json - npm package file for installation