Installing

DataTables and Editor are powerful libraries, but before you can use them, they need to be installed on your system! This guide walks through how to download the Node.JS example package for Editor and set it up. The end result will be the ability to run all of the Editor examples in your Node.JS environment, ready for you to experiment with, and then progress to using Editor in your own code, which is explained towards the end of the document.

This installation is a simple four step process which the documentation below will guide you though.

Example package

Download

To download the Editor Node.JS package, open the Editor download page and select the Editor Node.JS package. If you already have a DataTables account the download will start immediately. If you don't have a DataTables account you will be asked to create one to start a trial.

When the download completes, unzip the files and open the unzipped directory in a terminal. Use npm install to download and install the required packages from NPM (specifically datatables.net-editor-server for the Editor server-side libraries, and express to act as a server and router for the examples).

Examples SQL

With the Node package ready to run, we now need to load your database with the tables and data required for the Editor examples. The Node.JS libraries work with a number of different databases as Knex.JS is used as a database abstraction layer. Each database requires the demo SQL data file to be tailored for its own dialect. The following links contain the SQL needed for each of the supported databases:

Select the appropriate file for your database and then run the SQL contained within on your database access portal (SQL Server Management Studio, CLI, phpMyAdmin or pgAdmin3 for example). The demo SQL will create new tables and enter data into them. Note that they will overwrite any conflicting table names - installing into a new database is recommended, and also, as is good practice, ensure that you have backed up your database.

Database connection

The next step is to set up the database connection so the Editor libraries can interact with the server, reading and modified data as required. This is done with Knex.JS. The Knex.JS documentation does an excellent job of explaining its own connection options - you essentially just need to create a Knex connection and pass that on to the Editor Node.JS libraries to use.

A sample configuration might look like:

let knex = require('knex');

module.exports = knex({
    client: 'mysql', // pg, mssql, etc

    connection: {
        database:    '...',
        host:        '...',
        password:    '...',
        user:        '...',
        dateStrings: true
    }
});

In the examples package, this database connection configuration is contained inside the db.js file. Edit this file in your preferred text editor by simply filling in the connection parameters, and changing the database type if required.

Running the examples

With the demo SQL installed and a database connection configured, all we need to do now is run the examples:

npm start

Your terminal will show a message indicating the address that you will be able to use to launch a browser and interact with the examples - e.g.:

DataTables Editor demo - navigate to http://localhost:8081:/

Integrating with your own code

To make use of the Editor Node.JS libraries with your own code (i.e. somewhere other than the example package), use:

npm install datatables.net-editor-server

Then in your Javascript files:

let e = require('datatables.net-editor-server');

let Editor = e.Editor;
let Field = e.Field;
let Validate = e.Validate;
let Format = e.Format;

Next steps

With the examples running or the libraries included in your own code, the next step is to start experimenting with the examples and understanding how the Editor Node.JS code operates!