Create a new DataTable instance for getting data from a database.
Optionaldb: Knex<any, any[]>Database connection object
Optionaltable: string | string[]The table name in the database to read and write information from and to. Can be given here or with the 'table' method.
Optionalpkey: string | string[]Primary key column name in the table given in
Get a column based on its name
Column name
Column, or throws if no column found
Get the database connection assigned to the instance.
Knex db interface
Get the debug setting for this instance
Debug enabled (true) or not
Set the debug setting for this instance
Debug flag
Self for chaining
Get the id prefix.
Typically primary keys are numeric and this is not a valid ID value in an HTML document - is also increases the likelihood of an ID clash if multiple tables are used on a single page. As such, a prefix is assigned to the primary key value for each row, and this is used as the DOM ID,
id prefix
Get the configured Mjoin instances.
Note that for the majority of use cases you will want to use the
leftJoin() method. It is significantly easier to use if you are just
doing a simple left join!
The list of Join instances that Editor will join the parent table to (i.e. the one that the Editor.table and Editor.fields methods refer to in this class instance).
Array of Mjoin instances
Add a left join condition to the DataTable instance, allowing it to
operate over multiple tables. Multiple leftJoin() calls can be made for
a single DataTable instance to join multiple tables.
In this form the method will take a function as the second parameter which is a Knex callback function allowing a complex join expression to be built.
Table name to do a join onto
Self for chaining
Add a left join condition to the DataTable instance, allowing it to
operate over multiple tables. Multiple leftJoin() calls can be made for
a single DataTable instance to join multiple tables.
A left join is the most common type of join that is used with DataTable so this method is provided to make its use very easy to configure. Its parameters are basically the same as writing an SQL left join statement.
Table name to do a join onto
Column name from the parent table to use as the join link
Join condition (=, '<`, etc)
Column name from the child table to use as the join link
Self for chaining
Add an event listener. The DataTable class will trigger an number of
events that some action can be taken on.
Event name
Event callback function that will be executed when the event occurs.
Self for chaining.
Get the primary key value.
The primary key must be known to DataTable so it will know which rows are being edited / deleted upon those actions. The default value is ['id'].
Array of column names
Set the primary key value(s)
Primary key column name. Use an array of strings if using a compound key.
Self for chaining.
Process a request from the DataTable client-side to get / set data.
Form data sent from the client-side - e.g. req.body
File information, used for upload requests - e.g.
req.files
Promise that is fulfilled when Editor has completed its processing - result is the Editor instance.
Get the table name.
The table name designated which DB table DataTable will use as its data
source for working with the database. Table names can be given with an
alias, which can be used to simplify larger table names. The field
names would also need to reflect the alias, just like an SQL query. For
example: users as a.
Configured table name
Set the table name.
Database table name to use
Self for chaining
Get the array of conditions applied to the method.
Knex where conditions.
Set a condition for the queries Editor will perform. Editor uses Knex to connect to the database, and exposes the knex object using this method so you can add any conditions you like that are supported by Knex.
Knex query condition
Self for chaining.
This class let's you define the structure of a database, in order for it to be read and the data returned to DataTables.
Typically you will:
You may also wish to add query conditions, or provide extra pre-column options for features such as ColumnControl.