Class: Editor

DataTables Editor v1.2.4 documentation

Navigation

Hiding private elements (toggle)
Showing extended elements (toggle)
new Editor(oInit)

Editor is a plug-in for DataTables which provides an interface for creating, reading, editing and deleting and entries (a CRUD interface) in a DataTable. The documentation presented here is primarily focused on presenting the API for Editor. For a full list of features, examples and the server interface protocol, please refer to the Editor web-site.

Note that in this documentation, for brevity, the DataTable refers to the jQuery parameter jQuery.fn.dataTable through which it may be accessed. Therefore, when creating a new Editor instance, use jQuery.fn.Editor as shown in the examples below.

Constructor

Parameters:
Name Type Attributes Default Description
1
oInitobjectOptional{}

Configuration object for Editor. Options are defined by Editor.defaults. The options which must be set are ajaxUrl and domTable.

Example:
   // Basic initialisation - this example shows a table with 2 columns, each of which is editable
   // as a text input and provides add, edit and delete buttons by making use of TableTools
   // (Editor provides three buttons that extend the abilities of TableTools).
   $(document).ready(function() {
     var editor = new $.fn.Editor( {
       "ajaxUrl": "php/index.php",
       "domTable": "#example",
       "fields": [ {
           "label": "Browser:",
           "name": "browser"
         }, {
           "label": "Rendering engine:",
           "name": "engine"
         }, {
           "label": "Platform:",
           "name": "platform"
         }, {
           "label": "Version:",
           "name": "version"
         }, {
           "label": "CSS grade:",
           "name": "grade"
         }
       ]
     } );

     $('#example').dataTable( {
       "sDom": "Tfrtip",
       "sAjaxSource": "php/index.php",
       "aoColumns": [
         { "mData": "browser" },
         { "mData": "engine" },
         { "mData": "platform" },
         { "mData": "version", "sClass": "center" },
         { "mData": "grade", "sClass": "center" }
       ],
       "oTableTools": {
         "sRowSelect": "multi",
         "aButtons": [
           { "sExtends": "dte_create", "dte": editor },
           { "sExtends": "dte_edit",   "dte": editor },
           { "sExtends": "dte_remove", "dte": editor }
         ]
       }
     } );
   } );

Requires

  • jQuery 1.7+
  • DataTables 1.9+
  • TableTools 2.1+ - note that TableTools is only required if you want to use the row selection and button controls TableTools provides, but is not mandatory for Editor. If used, the TableTools should be loaded before Editor.

Summary

Namespaces

classes

Class names that are used by Editor for its various display components. A copy of this object is taken when an Editor instance is initialised, thus allowing different classes to be used in different instances if required. Class name changes can be useful for easy integration with CSS frameworks, for example Twitter Bootstrap.

defaults

Initialisation options that can be given to Editor at initialisation time.

display

Display controllers. See Editor.models.displayController for full information about the display controller options for Editor. The display controllers given in this object can be utilised by specifying the Editor.defaults.display option.

fieldTypes

Field types array - this can be used to add field types or modify the pre-defined options. By default Editor provides the following field tables (these can be readily modified, extended or added to using field type plug-ins if you wish to create a custom input control):

  • hidden - A hidden field which cannot be seen or modified by the user
  • readonly - Input where the value cannot be modified
  • text - Text input
  • password - Text input but bulleted out text
  • textarea - Textarea input for larger text inputs
  • select - Single select list
  • checkbox - Checkboxs
  • radio - Radio buttons
  • date - Date input control (requires jQuery UI's datepicker)
models

Object models container, for the various models that DataTables has available to it. These models define the objects that are used to hold the active state and configuration of the table.

Properties - static

<static, constant> VERSION :String

DataTables Editor version

Methods - instance

add(field)

Add a new field to the from. This is the method that is called automatically when fields are given in the initialisation objects as Editor.defaults.fields.

buttons(buttons)

Setup the buttons that will be shown in the footer of the form - calling this method will replace any buttons which are currently shown in the form.

clear(fieldName)

Remove fields from the form (fields are those that have been added using the Editor#add method or the fields initialisation option). A single, multiple or all fields can be removed at a time based on the passed parameter. Fields are identified by the name property that was given to each field when added to the form.

close(trigger)

Close the form display

create(title, buttons, show)

Create a new record - show the form that allows the user to enter information for a new row and then subsequently submit that data.

disable(name)

Disable one or more field inputs, disallowing subsequent user interaction with the fields until they are re-enabled.

edit(row, title, buttons, show)

Edit a record - show the form, pre-populated with the data that is in the given DataTables row, that allows the user to enter information for the row to be modified and then subsequently submit that data.

enable(name)

Enable one or more field inputs, restoring user interaction with the fields.

error(name, msg)

Show that a field, or the form globally, is in an error state. Note that errors are cleared on each submission of the form.

field(name) → {object}

Get a field object, configured for a named field, which can then be manipulated through its API. This function effectively acts as a proxy to the field extensions, allowing easy access to the methods for a named field. The methods that are available depend upon the field type plug-in for Editor. [...]

fields() → {string[]}

Get a list of the fields that are used by the Editor instance.

get(name) → {*|array}

Get the value of a field

hide(name)

Remove a field from the form display. Note that the field will still be submitted with the other fields in the form, but it simply won't be visible to the user.

message(name, msg)

Show an information message for the form as a whole, or for an individual field. This can be used to provide helpful information to a user about an individual field, or more typically the form (for example when deleting a record and asking for confirmation).

node(name)

Get the container node for an individual field.

off(name, fn)

Remove a bound event listener to the editor instance. This method provides a shorthand way of binding jQuery events that would be the same as writing $(editor).off(...) for convenience. Note that also the jQuery 1.7+ method off is used for this method, it will also work with older versions of jQuery, where it will use unbind.

on(name, fn)

Listen for an event which is fired off by Editor when it performs certain actions. This method provides a shorthand way of binding jQuery events that would be the same as writing $(editor).on(...) for convenience. Note that also the jQuery 1.7+ method on is used for this method, it will also work with older versions of jQuery, where it will use bind.

open()

Display the form to the end user in the web-browser

order(set)

Get or set the ordering of fields, as they are displayed in the form. When used as a getter, the field names are returned in an array, in their current order, and when used as a setting you can alter the field ordering by passing in an array with all field names in their new order. [...]

remove(rows, title, buttons, show)

Remove (delete) entries from the table. The rows to remove are given as either a single DOM node or an array of DOM nodes (including a jQuery object).

set(name, val)

Set the value of a field

show(name)

Show a field in the display that was previously hidden.

submit(successCallback, errorCallback, formatdata, hide)

Submit a form to the server for processing. The exact action performed will depend on which of the methods Editor#create, Editor#edit or Editor#remove were called to prepare the form - regardless of which one is used, you call this method to submit data.

title(title)

Set the title of the form

Events

onClose

Form hidden event, fired when the form is removed from the document. The of the compliment onOpen event.

onCreate

Create new row event, fired when a new row has been created in the DataTable by a form submission. This is called just after the fnAddData call to the DataTable.

onEdit

Edit row event, fired when a row has been edited in the DataTable by a form submission. This is called just after the fnUpdate call to the DataTable.

onInitComplete

Initialisation of the Editor instance has been completed.

onInitCreate

Create method activated event, fired when the create API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the create state.

onInitEdit

Edit method activated event, fired when the edit API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the edit state.

onInitRemove

Remove method activated event, fired when the remove API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the remove state.

onOpen

Form displayed event, fired when the form is made available in the DOM. This can be useful for fields that require height and width calculations to be performed since the element is not available in the document until the form is displayed.

onPostCreate

As per the onCreate event - included for naming consistency.

onPostEdit

As per the onEdit event - included for naming consistency.

onPostRemove

As per the onPostRemove event - included for naming consistency.

onPostRemove

Set data event, fired when the data is gathered from the form to be used to update the DataTable. This is a "global" version of onPreCreate, onPreEdit and onPreRemove and can be used to manipulate the data that will be added to the DataTable for all three actions

onPostSubmit

Post-submit event for the form, fired immediately after the data has been loaded by the Ajax call, allowing modification or any other interception of the data returned form the server.

onPreClose

Before a form is closed, this event is fired. It allows the close action to be cancelled by returning false from the function. This can be useful for confirming that the user actually wants to close the display (if they have unsaved changes for example).

onPreCreate

Pre-create new row event, fired just before DataTables calls the fnAddData method to add new data to the DataTable, allowing modification of the data that will be used to insert into the table.

onPreEdit

Pre-edit row event, fired just before DataTables calls the fnUpdate method to edit data in a DataTables row, allowing modification of the data that will be used to update the table.

onPreOpen

Before a form is displayed, this event is fired. It allows the open action to be cancelled by returning false from the function.

onPreRemove

Pre-remove row event, fired just before DataTables calls the fnDeleteRow method to delete a DataTables row.

onPreSubmit

Pre-submit event for the form, fired just before the data is submitted to the server. This event allows you to modify the data that will be submitted to the server. Note that this event runs after the 'formatdata' callback function of the Editor#submit API method.

onProcessing

Processing event, fired when Editor submits data to the server for processing. This can be used to provide your own processing indicator if your UI framework already has one.

onRemove

Row removed event, fired when a row has been removed in the DataTable by a form submission. This is called just after the fnDeleteRow call to the DataTable.

onSubmitComplete

Submission complete event, fired when data has been submitted to the server and after any of the return handling code has been run (updating the DataTable for example). Note that unlike onSubmitSuccess and onSubmitError, onSubmitComplete will be fired for both a successful submission and an error. Additionally this event will be fired after onSubmitSuccess or onSubmitError.

onSubmitError

Submission complete, but in error event, fired when data has been submitted to the server but an error occurred on the server (typically a JSON formatting error)

onSubmitSuccess

Submission complete and successful event, fired when data has been successfully submitted to the server and all actions required by the returned data (inserting or updating a row) have been completed.

Details

Properties - static

<static, constant> VERSION :String

DataTables Editor version

Methods - instance

add(field)

Add a new field to the from. This is the method that is called automatically when fields are given in the initialisation objects as Editor.defaults.fields.

Parameters:
Name Type Attributes Default Description
1
fieldobject | array

The object that describes the field (the full object is described by Editor.model.field. Note that multiple fields can be given by passing in an array of field definitions.

field.namestring

The name for the field that is submitted to the server. This is the only mandatory parameter in the field description object.

field.dataPropstring<optional>

The data property (mData in DataTables terminology) that is used to read from and write to the table. If not given then it will take the same value as the name that is given in the field object. Note that dataProp, like its DataTables counterpart, can use Javascript dotted object notation to use nested properties from the data source (e.g. "details.name").

field.defaultstring<optional>

The default value to set the input to when using the Editor#create method to add a new record.

field.labelstring<optional>

The label to display for the field input (i.e. the name that is visually assigned to the field).

field.typestring<optional>

The input control that is presented to the end user. The options available are defined by Editor.fieldTypes and any extensions made to that object.

field.fieldInfostring<optional>

Helpful information text about the field that is shown below the input control.

field.labelInfostring<optional>

Helpful information text about the field that is shown below the field label.

field.classNamestring<optional>

Class to assign to the field's container element.

Examples:
     // Add a single field to an Editor instance with basic name and label information
     var editor = new $.fn.Editor( {
       "ajaxUrl": "php/index.php",
       "domTable": "#example"
     } );
     
     editor.add( {
       "label": "Name:",
       "name": "name"
     } );

 
     // Add a field to an existing Editor instance with extra information
     editor.add( {
       "label": "Name:",
       "name": "name",
       "dataProp": "user_name",
       "fieldInfo": "Enter the system user name (first name + last name)"
     } );
buttons(buttons)

Setup the buttons that will be shown in the footer of the form - calling this method will replace any buttons which are currently shown in the form.

Parameters:
Name Type Attributes Default Description
1
buttonsarray | object

A single button definition to add to the form or an array of objects with the button definitions to add more than one button. The options for the button definitions are fully defined by the Editor.models.button object.

buttons.labelstring

The text to put into the button. This can be any HTML string you wish as it will be rendered as HTML (allowing images etc to be shown inside the button).

buttons.fnfunction<optional>

Callback function which the button is activated. For example for a 'submit' button you would call the Editor#submit method, while for a cancel button you would call the Editor#close method. Note that the function is executed in the scope of the Editor instance, so you can call the Editor's API methods using the this keyword.

buttons.classNamestring<optional>

The CSS class(es) to apply to the button which can be useful for styling buttons which preform different functions each with a distinctive visual appearance.

Examples:
     // Create an editor instance and then setup a submit button
     var editor = new $.fn.Editor( {
       "ajaxUrl": "php/index.php",
       "domTable": "#example"
     } );
     
     editor.buttons( {
       "label": "Submit",
       "fn": function () {
         this.submit();
       }
     } );
     
 
     // Put save (submit) and cancel buttons onto a pre-existing editor instance
     editor.buttons( [
       {
         "label": "Cancel",
         "fn": function () {
           this.close();
         }
       }, {
         "label": "Save",
         "fn": function () {
           this.submit();
         }
       }
     ] );
clear(fieldName)

Remove fields from the form (fields are those that have been added using the Editor#add method or the fields initialisation option). A single, multiple or all fields can be removed at a time based on the passed parameter. Fields are identified by the name property that was given to each field when added to the form.

Parameters:
Name Type Attributes Default Description
1
fieldNamestring | arrayOptional

Field or fields to remove from the form. If not given then all fields are removed from the form. If given as a string then the single matching field will be removed. If given as an array of strings, then all matching fields will be removed.

Examples:
   // Clear the form of current fields and then add a new field 
   // before displaying a 'create' display
   editor.clear();
   editor.add( {
     "label": "User name",
     "name": "username"
   } );
   editor.create( "Create user" );

 
   // Remove an individual field
   editor.clear( "username" );

 
   // Remove multiple fields
   editor.clear( [ "first_name", "last_name" ] );
close(trigger)

Close the form display

Parameters:
Name Type Attributes Default Description
1
triggerstringOptional

An identification string to indicate what called the close method. This is entirely optional, but could be useful in the events / callback functions. For example the display controller will pass in either 'background' or 'icon' to indicate if the close was triggered by a click on the background or the close icon.

Example:
     // Show the 'create' form with a cancel button that will call this
     // method when activated.
     editor.create( 'Add new record', [
       {
         "label": "Cancel",
         "fn": function () {
           this.close();
         }
       }, {
         "label": "Save",
         "fn": function () {
           this.submit();
         }
       }
     ] );
create(title, buttons, show)

Create a new record - show the form that allows the user to enter information for a new row and then subsequently submit that data.

Parameters:
Name Type Attributes Default Description
1
titlestringOptional

The title to show in the form header

2
buttonsobject | arrayOptional

The buttons to use in the display. If not given or null, then the buttons already setup for the form (using the Editor#buttons method) will be used

3
showbooleanOptionaltrue

Show the form or not. If false the form is not shown to the user, which can be useful when no confirmation is required for an action.

Examples:
   // Show the create form with a submit button
   editor.create( 'Add new record', {
     "label": "Save",
     "fn": function () { this.submit(); }
   } );

 
   // Don't show the form and automatically submit it after programatically 
   // setting the values of fields (and using the field defaults)
   editor.create( null, null, false );
   editor.set( 'name', 'Test user' );
   editor.set( 'access', 'Read only' );
   editor.submit();
disable(name)

Disable one or more field inputs, disallowing subsequent user interaction with the fields until they are re-enabled.

Parameters:
Name Type Attributes Default Description
1
namestring | array

The field name (from the name parameter given when originally setting up the field) to disable, or an array of field names to disable multiple fields with a single call.

Examples:
   // Show a 'create' record form, but with a field disabled
   editor.disable( 'account_type' );
   editor.create( 'Add new user', {
     "label": "Save",
     "fn": function () { this.submit(); }
   } );

 
   // Disable multiple fields by using an array of field names
   editor.disable( ['account_type', 'access_level'] );
edit(row, title, buttons, show)

Edit a record - show the form, pre-populated with the data that is in the given DataTables row, that allows the user to enter information for the row to be modified and then subsequently submit that data.

Parameters:
Name Type Attributes Default Description
1
rownode

The TR element from the DataTable that is to be edited

2
titlestringOptional

The title to show in the form header

3
buttonsobject | arrayOptional

The buttons to use in the display. If not given or null, then the buttons already setup for the form (using the Editor#buttons method) will be used

4
showbooleanOptionaltrue

Show the form or not. If false the form is not shown to the user, which can be useful when no confirmation is required for an action.

Examples:
   // Show the edit form for the first row in the DataTable with a submit button
   editor.edit( $('#example tbody tr:eq(0)')[0], 'Edit record', {
     "label": "Update",
     "fn": function () { this.submit(); }
   } );

 
   // Use the title and buttons API methods to show an edit form (this provides
   // the same result as example above, but is a different way of achieving it
   editor.title( 'Edit record' );
   editor.buttons( {
     "label": "Update",
     "fn": function () { this.submit(); }
   } );
   editor.edit( $('#example tbody tr:eq(0)')[0] );

 
   // Automatically submit an edit without showing the user the form
   editor.edit( TRnode, null, null, false );
   editor.set( 'name', 'Updated name' );
   editor.set( 'access', 'Read only' );
   editor.submit();
enable(name)

Enable one or more field inputs, restoring user interaction with the fields.

Parameters:
Name Type Attributes Default Description
1
namestring | array

The field name (from the name parameter given when originally setting up the field) to enable, or an array of field names to enable multiple fields with a single call.

Example:
   // Show a 'create' form with buttons which will enable and disable certain fields
   editor.create( 'Add new user', [
     {
       "label": "User name only",
       "fn": function () {
         this.enable('username');
         this.disable( ['first_name', 'last_name'] );
       }
     }, {
       "label": "Name based",
       "fn": function () {
         this.disable('username');
         this.enable( ['first_name', 'last_name'] );
       }
     }, {
       "label": "Submit",
       "fn": function () { this.submit(); }
     }
   );
error(name, msg)

Show that a field, or the form globally, is in an error state. Note that errors are cleared on each submission of the form.

Parameters:
Name Type Attributes Default Description
1
namestringOptional

The name of the field that is in error. If not given then the global form error display is used.

2
msgstring

The error message to show

Examples:
   // Show an error if the field is required
   editor.create( 'Add new user', {
     "label": "Submit",
     "fn": function () {
       if ( this.get('username') === '' ) {
         this.error( 'username', 'A user name is required' );
         return;
       }
       this.submit();
     }
   } );

 
   // Show a field and a global error for a required field
   editor.create( 'Add new user', {
     "label": "Submit",
     "fn": function () {
       if ( this.get('username') === '' ) {
         this.error( 'username', 'A user name is required' );
         this.error( 'The data could not be saved because it is incomplete' );
         return;
       }
       this.submit();
     }
   } );
field(name) → {object}

Get a field object, configured for a named field, which can then be manipulated through its API. This function effectively acts as a proxy to the field extensions, allowing easy access to the methods for a named field. The methods that are available depend upon the field type plug-in for Editor.

For developers, note that the configuration object for the field is prefixed to the arguments array for the method called.

Parameters:
Name Type Attributes Default Description
1
namestring

Field name to be obtained

Returns:

Editor.fieldTypes object, with its API methods wrapped by a closure to automatically pass in the field configuration object for the named field.

Examples:
    // Update the values available in a select list
    editor.field('island').update( [
      'Lewis and Harris',
      'South Uist',
      'North Uist',
      'Benbecula',
      'Barra'
    ] );

  
    // Equivalent calls
    editor.field('name').set('John Smith');

    // results in the same action as:
    editor.set('John Smith');
fields() → {string[]}

Get a list of the fields that are used by the Editor instance.

Returns:

Array of field names

Example:
   // Get current fields and move first item to the end
   var fields = editor.fields();
   var first = fields.shift();
   fields.push( first );
   editor.order( fields );
get(name) → {*|array}

Get the value of a field

Parameters:
Name Type Attributes Default Description
1
namestringOptional

The field name (from the name parameter given when originally setting up the field) to disable. If not given, then an object of fields is returned, with the value of each field from the instance represented in the array (the object properties are the field names).

Returns:

Value from the named field

Example:
   // Client-side validation - check that a field has been given a value 
   // before submitting the form
   editor.create( 'Add new user', {
     "label": "Submit",
     "fn": function () {
       if ( this.get('username') === '' ) {
         this.error( 'username', 'A user name is required' );
         return;
       }
       this.submit();
     }
   } );
hide(name)

Remove a field from the form display. Note that the field will still be submitted with the other fields in the form, but it simply won't be visible to the user.

Parameters:
Name Type Attributes Default Description
1
namestring | arrayOptional

The field name (from the name parameter given when originally setting up the field) to hide or an array of names. If not given then all fields are hidden.

Examples:
   // Show a 'create' record form, but with some fields hidden
   editor.hide( 'account_type' );
   editor.hide( 'access_level' );
   editor.create( 'Add new user', {
     "label": "Save",
     "fn": function () { this.submit(); }
   } );

 
   // Show a single field by hiding all and then showing one
   editor.hide();
   editor.show('access_type');
message(name, msg)

Show an information message for the form as a whole, or for an individual field. This can be used to provide helpful information to a user about an individual field, or more typically the form (for example when deleting a record and asking for confirmation).

Parameters:
Name Type Attributes Default Description
1
namestringOptional

The name of the field to show the message for. If not given then a global message is shown for the form

2
msgstring

The message to show

Examples:
   // Show a global message for a 'create' form
   editor.message( 'Add a new user to the database by completing the fields below' );
   editor.create( 'Add new user', {
     "label": "Submit",
     "fn": function () { this.submit(); }
   } );

 
   // Show a message for an individual field when a 'help' icon is clicked on
   $('#user_help').click( function () {
     editor.message( 'user', 'The user name is what the system user will login with' );
   } );
node(name)

Get the container node for an individual field.

Parameters:
Name Type Attributes Default Description
1
namestring

The field name (from the name parameter given when originally setting up the field) to get the DOM node for.

Example:
   // Dynamically add a class to a field's container
   $(editor.node( 'account_type' )).addClass( 'account' );
off(name, fn)

Remove a bound event listener to the editor instance. This method provides a shorthand way of binding jQuery events that would be the same as writing $(editor).off(...) for convenience. Note that also the jQuery 1.7+ method off is used for this method, it will also work with older versions of jQuery, where it will use unbind.

Parameters:
Name Type Attributes Default Description
1
namestring

Event name to remove the listeners for - event names are defined by Editor.

2
fnfunctionOptional

The function to remove. If not given, all functions which are assigned to the given event name will be removed.

Example:
   // Add an event to alert when the form is shown and then remove the listener
   // so it will only fire once
   editor.on( 'onOpen', function () {
     alert('Form displayed!');
     editor.off( 'onOpen' );
   } );
on(name, fn)

Listen for an event which is fired off by Editor when it performs certain actions. This method provides a shorthand way of binding jQuery events that would be the same as writing $(editor).on(...) for convenience. Note that also the jQuery 1.7+ method on is used for this method, it will also work with older versions of jQuery, where it will use bind.

Parameters:
Name Type Attributes Default Description
1
namestring

Event name to add the listener for - event names are defined by Editor.

2
fnfunction

The function to run when the event is triggered.

Example:
   // Log events on the console when they occur
   editor.on( 'onOpen', function () { console.log( 'Form opened' ); } );
   editor.on( 'onClose', function () { console.log( 'Form closed' ); } );
   editor.on( 'onSubmit', function () { console.log( 'Form submitted' ); } );
open()

Display the form to the end user in the web-browser

Example:
   // Build a 'create' form, but don't display it until some values have
   // been set. When done, then display the form.
   editor.create( 'Create user', {
     "label": "Submit",
     "fn": function () { this.submit(); }
   }, false );
   editor.set( 'name', 'Test user' );
   editor.set( 'access', 'Read only' );
   editor.open();
order(set)

Get or set the ordering of fields, as they are displayed in the form. When used as a getter, the field names are returned in an array, in their current order, and when used as a setting you can alter the field ordering by passing in an array with all field names in their new order.

Note that all fields must be included when reordering, and no additional fields can be added here (use Editor#add to add more fields). Finally, for setting the order, you can pass an array of the field names, or give the field names as individual parameters (see examples below).

Parameters:
Name Type Attributes Default Description
1
setarray | stringOptional

Field order to set.

Examples:
   // Get field ordering
   var order = editor.order();

 
   // Set the field order
   var order = editor.order();
   order.unshift( order.pop() ); // move the last field into the first position
   editor.order( order );

 
   // Set the field order as arguments
   editor.order( "pupil", "grade", "dept", "exam-board" );
remove(rows, title, buttons, show)

Remove (delete) entries from the table. The rows to remove are given as either a single DOM node or an array of DOM nodes (including a jQuery object).

Parameters:
Name Type Attributes Default Description
1
rowsnode | array

The row, or array of nodes, to delete

2
titlestringOptional

The title to show in the form header

3
buttonsobject | arrayOptional

The buttons to use in the display. If not given or null, then the buttons already setup for the form (using the Editor#buttons method) will be used

4
showbooleanOptionaltrue

Show the form or not. If false the form is not shown to the user, which can be useful when no confirmation is required for an action.

Examples:
   // Delete a given row with a message to let the user know exactly what is
   // happening
   editor.message( "Are you sure you want to remove this row?" );
   editor.remove( row_to_delete, 'Delete row', {
     "label": "Confirm",
     "fn": function () { this.submit(); }
   } );

 
   // Delete the first row in a table without asking the user for confirmation
   editor.remove( '', $('#example tbody tr:eq(0)')[0], null, false );
   editor.submit();

 
   // Delete all rows in a table with a submit button
   editor.remove( $('#example tbody tr'), 'Delete all rows', {
     "label": "Delete all",
     "fn": function () { this.submit(); }
   } );
set(name, val)

Set the value of a field

Parameters:
Name Type Attributes Default Description
1
namestring

The field name (from the name parameter given when originally setting up the field) to disable.

2
val*

The value to set the field to. The format of the value will depend upon the field type.

Example:
   // Set the values of a few fields before then automatically submitting the form
   editor.create( null, null, false );
   editor.set( 'name', 'Test user' );
   editor.set( 'access', 'Read only' );
   editor.submit();
show(name)

Show a field in the display that was previously hidden.

Parameters:
Name Type Attributes Default Description
1
namestring | arrayOptional

The field name (from the name parameter given when originally setting up the field) to make visible, or an array of field names to make visible. If not given all fields are shown.

Examples:
   // Shuffle the fields that are visible, hiding one field and making two
   // others visible before then showing the Editor#create record form.
   editor.hide( 'username' );
   editor.show( 'account_type' );
   editor.show( 'access_level' );
   editor.create( 'Add new user', {
     "label": "Save",
     "fn": function () { this.submit(); }
   } );

 
   // Show all fields
   editor.show();
submit(successCallback, errorCallback, formatdata, hide)

Submit a form to the server for processing. The exact action performed will depend on which of the methods Editor#create, Editor#edit or Editor#remove were called to prepare the form - regardless of which one is used, you call this method to submit data.

Parameters:
Name Type Attributes Default Description
1
successCallbackfunctionOptional

Callback function that is executed once the form has been successfully submitted to the server and no errors occurred.

2
errorCallbackfunctionOptional

Callback function that is executed if the server reports an error due to the submission (this includes a JSON formatting error should the error return invalid JSON).

3
formatdatafunctionOptional

Callback function that is passed in the data that will be submitted to the server, allowing pre-formatting of the data, removal of data or adding of extra fields.

4
hidebooleanOptionaltrue

When the form is successfully submitted, by default the form display will be hidden - this option allows that to be overridden.

Examples:
   // Submit data from a form button
   editor.create( 'Add new record', {
     "label": "Save",
     "fn": function () {
       this.submit();
     }
   } );

 
   // Submit without showing the user the form
   editor.create( null, null, false );
   editor.submit();

 
   // Provide success and error callback methods
   editor.create( 'Add new record', {
     "label": "Save",
     "fn": function () {
       this.submit( function () {
           alert( 'Form successfully submitted!' );
         }, function () {
           alert( 'Form  encountered an error :-(' );
         }
       );
     }
   } );
 
 
   // Add an extra field to the data
   editor.create( 'Add new record', {
     "label": "Save",
     "fn": function () {
       this.submit( null, null, function (data) {
         data.extra = "Extra information";
       } );
     }
   } );

 
   // Don't hide the form immediately - change the title and then close the form
   // after a small amount of time
   editor.create( 'Add new record', {
     "label": "Save",
     "fn": function () {
       this.submit( 
         function () {
           var that = this;
           this.title( 'Data successfully added!' );
           setTimeout( function () {
             that.close();
           }, 1000 );
         },
         null,
         null,
         false
       );
     }
   } );
   
title(title)

Set the title of the form

Parameters:
Name Type Attributes Default Description
1
titlestring

The title to give to the form

Examples:
   // Create an edit display used the title, buttons and edit methods (note that
   // this is just an example, typically you would use the parameters of the edit
   // method to achieve this.
   editor.title( 'Edit record' );
   editor.buttons( {
     "label": "Update",
     "fn": function () { this.submit(); }
   } );
   editor.edit( TR_to_edit );

 
   // Show a create form, with a timer for the duration that the form is open
   editor.create( 'Add new record - time on form: 0s', {
     "label": "Save",
     "fn": function () { this.submit(); }
   } );
   
   // Add an event to the editor to stop the timer when the display is removed
   var runTimer = true;
   var timer = 0;
   editor.on( 'onClose', function () {
     runTimer = false;
     editor.off( 'onClose' );
   } );
   // Start the timer running
   updateTitle();

   // Local function to update the title once per second
   function updateTitle() {
     editor.title( 'Add new record - time on form: '+timer+'s' );
     timer++;
     if ( runTimer ) {
       setTimeout( function() {
         updateTitle();
       }, 1000 );
     }
   }

Events

onClose

Form hidden event, fired when the form is removed from the document. The of the compliment onOpen event.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

onCreate

Create new row event, fired when a new row has been created in the DataTable by a form submission. This is called just after the fnAddData call to the DataTable.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable

onEdit

Edit row event, fired when a row has been edited in the DataTable by a form submission. This is called just after the fnUpdate call to the DataTable.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable

onInitComplete

Initialisation of the Editor instance has been completed.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

onInitCreate

Create method activated event, fired when the create API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the create state.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

onInitEdit

Edit method activated event, fired when the edit API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the edit state.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
trnode

TR element of the row to be edited

3
dataarray | object

Data source array / object for the row to be edited

onInitRemove

Remove method activated event, fired when the remove API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the remove state.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
trsarray

Array of the TR elements for the removed to be deleted

3
dataarray

Array of the data source array / objects for the rows to be deleted. This is in the same index order as the TR nodes in the second parameter.

onOpen

Form displayed event, fired when the form is made available in the DOM. This can be useful for fields that require height and width calculations to be performed since the element is not available in the document until the form is displayed.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

onPostCreate

As per the onCreate event - included for naming consistency.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable

onPostEdit

As per the onEdit event - included for naming consistency.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable

onPostRemove

As per the onPostRemove event - included for naming consistency.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

onPostRemove

Set data event, fired when the data is gathered from the form to be used to update the DataTable. This is a "global" version of onPreCreate, onPreEdit and onPreRemove and can be used to manipulate the data that will be added to the DataTable for all three actions

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that will be used to update the DataTable

4
actionstring

The action being performed by the form - 'create', 'edit' or 'remove'.

onPostSubmit

Post-submit event for the form, fired immediately after the data has been loaded by the Ajax call, allowing modification or any other interception of the data returned form the server.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data object that was be submitted to the server

4
actionstring

The action type for this submit - create, edit or remove.

onPreClose

Before a form is closed, this event is fired. It allows the close action to be cancelled by returning false from the function. This can be useful for confirming that the user actually wants to close the display (if they have unsaved changes for example).

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
triggerstring

Action that caused the close event - can be undefined. Typically defined by the display controller.

onPreCreate

Pre-create new row event, fired just before DataTables calls the fnAddData method to add new data to the DataTable, allowing modification of the data that will be used to insert into the table.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that will be used to update the DataTable

onPreEdit

Pre-edit row event, fired just before DataTables calls the fnUpdate method to edit data in a DataTables row, allowing modification of the data that will be used to update the table.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that will be used to update the DataTable

onPreOpen

Before a form is displayed, this event is fired. It allows the open action to be cancelled by returning false from the function.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

onPreRemove

Pre-remove row event, fired just before DataTables calls the fnDeleteRow method to delete a DataTables row.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

onPreSubmit

Pre-submit event for the form, fired just before the data is submitted to the server. This event allows you to modify the data that will be submitted to the server. Note that this event runs after the 'formatdata' callback function of the Editor#submit API method.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
dataobject

The data object that will be submitted to the server

3
actionstring

The action type for this submit - create, edit or remove.

onProcessing

Processing event, fired when Editor submits data to the server for processing. This can be used to provide your own processing indicator if your UI framework already has one.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
processingboolean

Flag for if the processing is running (true) or not (false).

onRemove

Row removed event, fired when a row has been removed in the DataTable by a form submission. This is called just after the fnDeleteRow call to the DataTable.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

onSubmitComplete

Submission complete event, fired when data has been submitted to the server and after any of the return handling code has been run (updating the DataTable for example). Note that unlike onSubmitSuccess and onSubmitError, onSubmitComplete will be fired for both a successful submission and an error. Additionally this event will be fired after onSubmitSuccess or onSubmitError.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable

onSubmitError

Submission complete, but in error event, fired when data has been submitted to the server but an error occurred on the server (typically a JSON formatting error)

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
xhrobject

The Ajax object

3
errstring

The error message from jQuery

4
thrownobject

The exception thrown by jQuery

5
dataobject

The data that was used to update the DataTable

onSubmitSuccess

Submission complete and successful event, fired when data has been successfully submitted to the server and all actions required by the returned data (inserting or updating a row) have been completed.

Parameters:
Name Type Attributes Default Description
1
eevent

jQuery event object

2
jsonobject

The JSON object returned from the server

3
dataobject

The data that was used to update the DataTable