DataTables Editor - joined tables example

Data in relational databases is often stored over multiple tables, partitioned by the data type and then joined together using SQL JOIN queries. Editor makes working with multiple tables super easy through its, and DataTables', ability to work with nested Javascript objects.

In this example we have one master table (user accounts), and three 'child' tables that link to records in that master table (department, access and extra information). The access join is particularly interesting as it uses a link table to allow a single account to be linked to multiple access options. To display these options in DataTables we use the mData and mRender options (in this case, displaying the contents of the array from the server as a comma separated list). The department and extra columns use dotted JSON notation to display data, as that is what is retrieved from the server.

The server-side code for this example is also equally important, since that is what will do the JOIN SQL queries. To ensure that this is as easy as possible, Editor has a 'Join' class that can be used easily construct complex CRUD queries with the minimum of effort. For further information about using the PHP libraries to build an editable DataTable with JOINed tables, please see the PHP JOIN tutorial.

First name Last name Department Access
First name Last name Department Access

Initialisation code

The Javascript below is what is used on this page for the example shown.


				

Table HTML

The HTML shown below shows the TABLE that is used in this example.


				

Server-side PHP

The code below is that HTML that is used to drive the server-side section of this exampe.


				

Included media files:

The HTML shown below includes the Javascript and CSS files that are required for the Editor operation on this page. You can use this as a template for your own pages, but if you move the files you might need to update the paths.


				

Communication of Editor between the client and server:

Editor submits and retrieves information by Ajax requests. The two blocks below show the data that Editor submits and receives, to and from the server. This is updated live as you interact with Editor so you can see what is submitted.

Submitted data:

The following shows the data that has been submitted to the server when a request is made to add, edit or delete data from the table.

// No data yet submitted

Server response:

The following shows the data that has been returned by the server in response to the data submitted on the left and is then acted upon.

// No data yet received

Data for DataTables from server:

DataTables can request information to display from the server when the page first loads. The block below shows the response from the server.


				

Examples

Basic:
Advanced: