Creates an instance of Editor.
Optional
db: Knex<any, any[]> = nullDatabase connection object
Optional
table: string | string[] = nullThe table name in the database to read and write information from and to. Can be given here or with the 'table' method.
Optional
pkey: string | string[] = nullPrimary key column name in the table given in
Static
ActionStatic
versionGet the debug setting for this instance
Debug enabled (true) or not
Set the debug setting for this instance
Self for chaining
Debug flag
Add a debug message
Self for chaining
Message to add
Get the validate flag
Enable / disable validation. This would be used with after the
validate
method if you call that before process()
.
Self for chaining
true (default) = perform validation, false don't.
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, so Editor can track individual rows.
id prefix
Get the id prefix.
Self for chaining
Prefix to use.
Get the data that is being processed by the Editor instance. This is only
useful once the process()
method has been called, and is available for
use in validation and formatter methods.
Data that has been passed into ()
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 table and fields methods refer to in this class instance).
Array of Mjoin instances
Add one or more Mjoin instances.
Self for chaining.
Rest
...join: Mjoin[]Mjoin instance to add.
Add a left join condition to the Editor instance, allowing it to operate
over multiple tables. Multiple leftJoin()
calls can be made for a
single Editor 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.
Self for chaining
Table name to do a join onto
Add a left join condition to the Editor instance, allowing it to operate
over multiple tables. Multiple leftJoin()
calls can be made for a
single Editor instance to join multiple tables.
A left join is the most common type of join that is used with Editor 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, but in this case Editor will handle the create, update and remove requirements of the join for you:
Please note that when using join tables, Editor requires that you fully
qualify each field with the field's table name. SQL can result table
names for ambiguous field names, but for Editor to provide its full CRUD
options, the table name must also be given. For example the field
first_name
in the table users
would be given as users.first_name
.
Self for chaining
Table name to do a join onto
Field from the parent table to use as the join link
Join condition (=
, '<`, etc)
Field from the child table to use as the join link
Get the left join remove value.
Value
Indicate if a remove should be performed on left joined tables when deleting
from the parent row. Note that this is disabled by default and will be
removed completely in v2. Use ON DELETE CASCADE
in your database instead.
Self for chaining
Value
Add an event listener. The Editor
class will trigger an number of
events that some action can be taken on.
Self for chaining.
Event name
Event callback function that will be executed when the event occurs.
Get the primary key value.
The primary key must be known to Editor 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)
Self for chaining.
Optional
pkey: string | string[]Primary key column name. Use an array of strings if using a compound key.
Convert a primary key combined value to an array of field values.
Array of field values that the id was made up of
The id that should be split apart
Optional
flat: boolean = falseFlag to indicate if the returned array should be
flat (useful for where
conditions) or nested for join tables.
Optional
pkey: string[] = nullThe primary key name - will use the instance value if not given
Convert a primary key array of field values to a combined value.
The created primary key value.
The row of data that the primary key value should be extracted from.
Optional
flat: boolean = falseFlag to indicate if the given array is flat
(useful for where
conditions) or nested for join tables.
Process a request from the Editor client-side to get / set data.
Promise that is fulfilled when Editor has completed its processing - result is the Editor instance.
Form data sent from the client-side -
e.g. req.body
Optional
files: IUpload = nullFile information, used for upload
requests - e.g. req.files
Get CRUD read table name.
Configured read table name
Set CRUD read table name. If this method is used, Editor will create from the
table name(s) given rather than those given by Editor->table()
. This can be
a useful distinction to allow a read from a VIEW (which could make use of a
complex SELECT) while writing to a different table.
Self for chaining
Database table name to use for reading from
Get the database schema.
This is used if you are using multiple schema's in your database. By default Editor will not specify a schema, so the default search path will be used. This allows that to be overridden.
Schema
Set the database schema
Self for chaining
Schema to use.
Get the table name.
The table name designated which DB table Editor 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.
Self for chaining
Database table name to use
Get transaction support status
When enabled (which it is by default) Editor will use an SQL transaction to ensure data integrity while it is performing operations on the table. This can be optionally disabled using this method, if required by your database configuration.
true is transactions are enabled, false otherwise.
Set transaction support state
Self for chaining
Set the transaction status
Get the try/catch status.
Editor uses a try/catch in the process method, and it can be useful to disable this for debugging, but its not recommended you do that in production.
Try / catch status.
Set the try/catch state.
Self for chaining.
Value to set. true
will enable, false
disable.
Perform validation on a data set.
Note that validation is performed on data only when the action is
create
or edit
. Additionally, validation is performed on the wire
data - i.e. that which is submitted from the client, without formatting.
Any formatting required by setFormatter
is performed after the data
from the client has been validated.
true
if the data is valid, false
if not.
Output array to which field error information will
be written. Each element in the array represents a field in an error
condition. These elements are themselves arrays with two properties
set; name
and status
.
The format data to check
Get any global validator that has been set.
Global validator
Set a global validator. This will be triggered for the create, edit and remove actions performed from the client-side.
Self for chaining
Function to execute when validating the input data.
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.
Self for chaining.
Rest
...cond: any[]Knex query condition
Static
actionDetermine the request type from an HTTP request.
Indicates what action the request is
HTTP request - normally request.body
. Note that
if you are using body-parser
you should use { extended: true }
as its
options to ensure that nested properties are correctly resolved.
Generated using TypeDoc
DataTables Editor base class for creating editable tables.
Editor class instances are capable of servicing all of the requests that DataTables and Editor will make from the client-side - specifically:
The Editor instance is configured with information regarding the database table fields that you which to make editable, and other information needed to read and write to the database (table name for example!).
This documentation is very much focused on describing the API presented by these DataTables Editor classes. For a more general overview of how the Editor class is used, and how to install Editor on your server, please refer to the Editor manual.
Export