Options

Editor's basic operations can be customised through configuration options that are given to it when you initialise an Editor object. These options define how the instance will interface with the server, how the end user will interact with the form, and the fields that are contained in the form.

Setting options

Configuration of Editor is performed by passing the options you want defined into the Editor constructor, as object parameters. For example:

new DataTable.Editor( {
    ajax:  '/api/staff',
    table: '#staff'
} );

This uses the ajax and table options to define where the Ajax data should be set on form submission, and what DataTable element Editor should attach itself to, respectively.

Extending this example, as many configuration options as you wish can be used in the object (although each one only once of course!). In this case the display option is set to envelope to use the envelope display controller, as well as the two options defined before:

new DataTable.Editor( {
    ajax:    '/api/staff',
    table:   '#staff',
    display: 'envelope'
} );

The object being passed in is just a standard Javascript object and can be treated as such. Predefine it if needed, add as many options as you wish, etc!

For the full range of configuration options available for DataTables, please refer to the options reference section of this web-site.

Common options

The three most common options that you will find particularly useful when creating an Editor instance are:

  • ajax - Ajax configuration options for submission of data (this is optional as of v1.6 - when not given, Editor will modify a DataTable locally).
  • table - The DataTable to attach the Editor to
  • fields - The initial fields to show in the form
  • Full list of options

Field options

The fields configured by the objects in the fields array also have a number of configuration options that you will find particularly useful:

  • fields.name - Required The name of the field that is submitted to the server. This is also used as the source for where to read the fields data as well, unless the fields.data option is specified.
  • fields.label - Field label that the end user will see to identify the field
  • fields.def - Default value for the field
  • Full list of options

Setting defaults

Editor has default values for each of its configuration options (refer to the documentation for each option to see its default configuration), and it can often be useful to customise these defaults, particularly when working on a large project. This can be done using the DataTable.Editor.defaults option. This object takes all of the same parameters as the Editor initialisation object, but this case you are setting the default for all future initialisations of Editor.

In this example, we set a default Ajax URL, and enable the onBlur option for inline editing (formOptions.inline):

$.extend( true, DataTable.Editor.defaults, {
    ajax: '/api/staff',
    formOptions: {
        inline: {
            onBlur: true
        }
    }
} );