datatables.net-editor-server
    Preparing search index...

    Class DataTable

    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:

    • Create the instance
    • Define the columns
    • Process the request
    • Return JSON to the client-side

    You may also wish to add query conditions, or provide extra pre-column options for features such as ColumnControl.

    Index

    Constructors

    • Create a new DataTable instance for getting data from a database.

      Parameters

      • 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

      Returns DataTable

    Methods

    • Get the database connection assigned to the instance.

      Returns Knex

      Knex db interface

    • Set the database connection.

      Parameters

      • db: Knex

        Knex interface

      Returns Editor

      Self for chaining

    • Get the debug setting for this instance

      Returns boolean

      Debug enabled (true) or not

    • Set the debug setting for this instance

      Parameters

      • set: boolean

        Debug flag

      Returns DataTable

      Self for chaining

    • Add a debug message

      Parameters

      • message: any

        Message to add

      Returns DataTable

      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,

      Returns string

      id prefix

    • Get the id prefix.

      Parameters

      • idPrefix: string

        Prefix to use.

      Returns DataTable

      Self for chaining

    • 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).

      Returns Mjoin[]

      Array of Mjoin instances

    • Add one or more Mjoin instances.

      Parameters

      • ...join: Mjoin[]

        Mjoin instance to add.

      Returns DataTable

      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.

      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.

      Parameters

      • table: string

        Table name to do a join onto

      • condition: Function

      Returns DataTable

      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.

      Parameters

      • table: string

        Table name to do a join onto

      • field1: string

        Column name from the parent table to use as the join link

      • operator: string

        Join condition (=, '<`, etc)

      • field2: string

        Column name from the child table to use as the join link

      Returns DataTable

      Self for chaining

    • Add an event listener. The DataTable class will trigger an number of events that some action can be taken on.

      Parameters

      • name: string

        Event name

      • callback: Function

        Event callback function that will be executed when the event occurs.

      Returns DataTable

      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'].

      Returns string[]

      Array of column names

    • Set the primary key value(s)

      Parameters

      • pkey: string | string[]

        Primary key column name. Use an array of strings if using a compound key.

      Returns DataTable

      Self for chaining.

    • Process a request from the DataTable client-side to get / set data.

      Parameters

      • data: IDtRequest

        Form data sent from the client-side - e.g. req.body

      • files: IUpload | null = null

        File information, used for upload requests - e.g. req.files

      Returns Promise<DataTable>

      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.

      Returns string[]

      Configured table name

    • Set the table name.

      Parameters

      • table: string | string[]

        Database table name to use

      Returns DataTable

      Self for chaining

    • Get the array of conditions applied to the method.

      Returns any[]

      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.

      Parameters

      • ...cond: Where<any, unknown>[]

        Knex query condition

      Returns Editor

      Self for chaining.