Classes (0) | Namespaces (5) |
Properties (0) | Static properties (1) |
Methods (24) | Static methods (0) |
Events (24) |
Properties (0) | Static properties (1) |
Methods (24) | Static methods (0) |
Events (24) |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | oInit | object | Optional | {} | Configuration object for Editor. Options
are defined by Editor.defaults. The options which must be set
are |
// 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 } ] } } ); } );
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.
Initialisation options that can be given to Editor at initialisation time.
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.
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 userreadonly
- Input where the value cannot be modifiedtext
- Text inputpassword
- Text input but bulleted out texttextarea
- Textarea input for larger text inputsselect
- Single select listcheckbox
- Checkboxsradio
- Radio buttonsdate
- Date input control (requires jQuery UI's datepicker)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.
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.
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.
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 the form display
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 one or more field inputs, disallowing subsequent user interaction with the fields until they are re-enabled.
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 one or more field inputs, restoring user interaction with the fields.
Show that a field, or the form globally, is in an error state. Note that errors are cleared on each submission of the form.
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. [...]
Get a list of the fields that are used by the Editor instance.
Get the value of a field
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.
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).
Get the container node for an individual field.
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
.
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
.
Display the form to the end user in the web-browser
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 (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 the value of a field
Show a field in the display that was previously hidden.
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.
Set the title of the form
Form hidden event, fired when the form is removed from the document. The of the compliment onOpen event.
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.
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.
Initialisation of the Editor instance has been completed.
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.
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.
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.
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.
As per the onCreate event - included for naming consistency.
As per the onEdit event - included for naming consistency.
As per the onPostRemove event - included for naming consistency.
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
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.
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).
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.
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.
Before a form is displayed, this event is fired. It allows the open action to be cancelled by returning false from the function.
Pre-remove row event, fired just before DataTables calls the fnDeleteRow method to delete a DataTables row.
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.
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.
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.
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.
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)
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.
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | field | object | 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.name | string | The name for the field that is submitted to the server. This is the only mandatory parameter in the field description object. | |||
field.dataProp | string | <optional> | The data property ( | ||
field.default | string | <optional> | The default value to set the input to when using the Editor#create method to add a new record. | ||
field.label | string | <optional> | The label to display for the field input (i.e. the name that is visually assigned to the field). | ||
field.type | string | <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.fieldInfo | string | <optional> | Helpful information text about the field that is shown below the input control. | ||
field.labelInfo | string | <optional> | Helpful information text about the field that is shown below the field label. | ||
field.className | string | <optional> | Class to assign to the field's container element. |
// 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)" } );
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | buttons | array | 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.label | string | 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.fn | function | <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 | ||
buttons.className | string | <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. |
// 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(); } } ] );
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | fieldName | string | array | Optional | 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. |
// 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 the form display
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | trigger | string | Optional | 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. |
// 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 a new record - show the form that allows the user to enter information for a new row and then subsequently submit that data.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | title | string | Optional | The title to show in the form header | |
2 | buttons | object | array | Optional | 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 | show | boolean | Optional | true | 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. |
// 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 one or more field inputs, disallowing subsequent user interaction with the fields until they are re-enabled.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | array | The field name (from the |
// 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 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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | row | node | The TR element from the DataTable that is to be edited | ||
2 | title | string | Optional | The title to show in the form header | |
3 | buttons | object | array | Optional | 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 | show | boolean | Optional | true | 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. |
// 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 one or more field inputs, restoring user interaction with the fields.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | array | The field name (from the |
// 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(); } } );
Show that a field, or the form globally, is in an error state. Note that errors are cleared on each submission of the form.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Optional | The name of the field that is in error. If not given then the global form error display is used. | |
2 | msg | string | The error message to show |
// 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(); } } );
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Field name to be obtained |
Editor.fieldTypes object, with its API methods wrapped by a closure to automatically pass in the field configuration object for the named field.
// 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');
Get a list of the fields that are used by the Editor instance.
Array of field names
// 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 the value of a field
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Optional | The field name (from the |
Value from the named field
// 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(); } } );
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | array | Optional | The field name (from the |
// 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');
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).
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Optional | The name of the field to show the message for. If not given then a global message is shown for the form | |
2 | msg | string | The message to show |
// 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' ); } );
Get the container node for an individual field.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | The field name (from the |
// Dynamically add a class to a field's container $(editor.node( 'account_type' )).addClass( 'account' );
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
.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Event name to remove the listeners for - event names are defined by Editor. | ||
2 | fn | function | Optional | The function to remove. If not given, all functions which are assigned to the given event name will be removed. |
// 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' ); } );
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
.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | Event name to add the listener for - event names are defined by Editor. | ||
2 | fn | function | The function to run when the event is triggered. |
// 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' ); } );
Display the form to the end user in the web-browser
// 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();
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).
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | set | array | string | Optional | Field order to set. |
// 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 (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).
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | rows | node | array | The row, or array of nodes, to delete | ||
2 | title | string | Optional | The title to show in the form header | |
3 | buttons | object | array | Optional | 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 | show | boolean | Optional | true | 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. |
// 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 the value of a field
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | The field name (from the | ||
2 | val | * | The value to set the field to. The format of the value will depend upon the field type. |
// 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 a field in the display that was previously hidden.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | name | string | array | Optional | The field name (from the |
// 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 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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | successCallback | function | Optional | Callback function that is executed once the form has been successfully submitted to the server and no errors occurred. | |
2 | errorCallback | function | Optional | 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 | formatdata | function | Optional | 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 | hide | boolean | Optional | true | When the form is successfully submitted, by default the form display will be hidden - this option allows that to be overridden. |
// 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 ); } } );
Set the title of the form
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | title | string | The title to give to the form |
// 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 ); } }
Form hidden event, fired when the form is removed from the document. The of the compliment onOpen event.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |
Initialisation of the Editor instance has been completed.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | tr | node | TR element of the row to be edited | ||
3 | data | array | object | Data source array / object for the row to be edited |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | trs | array | Array of the TR elements for the removed to be deleted | ||
3 | data | array | 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. |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object |
As per the onCreate event - included for naming consistency.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |
As per the onEdit event - included for naming consistency.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |
As per the onPostRemove event - included for naming consistency.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server |
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
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that will be used to update the DataTable | ||
4 | action | string | The action being performed by the form - 'create', 'edit' or 'remove'. |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data object that was be submitted to the server | ||
4 | action | string | The action type for this submit - |
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).
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | trigger | string | Action that caused the close event - can be undefined. Typically defined by the display controller. |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that will be used to update the DataTable |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that will be used to update the DataTable |
Before a form is displayed, this event is fired. It allows the open action to be cancelled by returning false from the function.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object |
Pre-remove row event, fired just before DataTables calls the fnDeleteRow method to delete a DataTables row.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | data | object | The data object that will be submitted to the server | ||
3 | action | string | The action type for this submit - |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | processing | boolean | Flag for if the processing is running (true) or not (false). |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |
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)
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | xhr | object | The Ajax object | ||
3 | err | string | The error message from jQuery | ||
4 | thrown | object | The exception thrown by jQuery | ||
5 | data | object | The data that was used to update the DataTable |
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.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | e | event | jQuery event object | ||
2 | json | object | The JSON object returned from the server | ||
3 | data | object | The data that was used to update the DataTable |