PHP libraries
DataTable's PHP libraries are designed to make it super easy to create a script on the server-side that will provide an anchor point for any client-side interaction made by DataTables and its extensions.
Features
The DataTables PHP libraries have the following features:
- Easily read database data to display in DataTables
- Full support for editing data via Editor
- Server-side processing support for large data sets
- ColumnControl and SearchBuilder for advanced filtering
- StateRestore integration
- Multiple databases supported (MySQL, Postgres, SQL Server and SQLite)
- PHP 7 / 8 support.
The PHP libraries for DataTables can do this for you in just a few lines of code.
This section of the manual goes into detail about how to install, setup, configure and use the DataTables PHP libraries. Reference documentation is also available for DataTables's PHP libraries, which documents the API interfaces and options of the PHP classes in detail.
PHP libraries manual
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 Editor PHP package and set it up. The end result will be the ability to run all of the Editor examples on your own web-server, ready for you to customise and experiment with as you need. This installation is a simple four step process which this documentation will guide you though. Read more »
Reading Data
The DataTable class provides a read only interface to a database table, reading the data from the columns configured and returning it to the client-side for display in response to a DataTables ajax request. It also supports server-side processing for large data sets and advanced filtering options. Read more »
Editing
The Editor class is one of the main access points for processing requests from the server-side. It can handle all requests for reading and writing data to a database for a DataTable. The class instance will be configured with the fields that it should operate on. Read more »
Formatters
Often the data that is stored in the database is not in a format that is suitable for display or manipulate by the end user. A common example of this is a timestamp - the number of seconds since 1st January 1970 means little to anyone, even experienced developers, but it is a useful format to hold the data in, since it can be sorted and filtered quickly in the database. For this reason the Columns and Field classes provide formatter methods. Read more »
Joins
A cornerstone of CRUD applications is the ability to combine information from multiple SQL tables, representing the combined data as a common data set that the end user can easily understand and manipulate. Relational databases are, after all, designed for exactly this sort of data referencing. Often in CRUD applications, working with such joined data can significantly increase the complexity of the application and increase development time, Editor makes working with such join tables extremely easy through its leftJoin() method. Complex joins with full CRUD support can be added in just minutes. Read more »
One-to-many joins
The leftJoin() method of the DataTable and Editor classes is excellent when using a 1:1 relationship between joined tables and is optimised for that data structure. However, it doesn't support a one-to-many option due to the formatting of the generated SQL statement. To provide one-to-many support the DataTable API libraries include a Mjoin class. Read more »
Options
When building forms, there are many cases where you will want to present the end user with a list of options from which a value can be selected. The Options class is available in the DataTables PHP libraries to fulfill this need. It is attached to an individual Column or Field instance using ->options() and will resolve, based on its configuration, to a list of options for the field. Read more »
Where Conditions
When displaying data from a database to an end user you may require the ability to filter the data that the end user sees (for example based on account permissions or some other access permissions). In SQL you would do this with a WHERE condition - the DataTables PHP libraries also provide a where() method when reading data from the database to expose this functionality and allow complex conditional expressions. Read more »
Events
When working with complex data, it can often be useful to perform some additional action when Editor updates the database based on information from the client-side. This can take the form of modifying the Editor or Field instances for the action being taken, deleting files from the file system when rows are removed, or adding log information to a database about an action that a user has taken. To make this possible, the PHP Editor class provides an event listener / callback option similar to the events that the client-side Javascript will trigger. Read more »
Validation
Validation of data is a fundamentally important aspect of a CRUD application. You need to be sure that the data that the client is sending you is what you expect. This is not just for security reasons, protecting your data from misuse and intentional corruption, but also simply from unintentional mistakes in submitting data. Strings limited to a certain length, dates in a particular format and required fields are all common uses of data validation. Read more »
File Upload
The DataTables PHP libraries provide an Upload class that can be used with the upload and uploadMany field types to provide end users with the ability to upload files to a server. The goal of the Upload class is to make the server-side aspect of file uploading as simple as possible, while retaining the same flexibility that you would expect from the DataTables libraries. Read more »
Demo App
To get you started with the DataTables libraries and Editor on your own server (or development machine), we provide a demo application that includes all of the Editor examples on this site, including their server-side scripts and the SQL for the backing database. Read more »