Simple standalone editing

Editor's primary use is as an Editor for DataTables, however, it can also be used as a standalone form editor, which can be very useful for single dimension configuration parameters (i.e. those that don't directly lend themselves to display in a table). This ensures a consistent interface for your end users in their form editing, and for you in your development API.

Editor's standalone mode is activated by simply not using a table parameter in the initialisation configuration object. The HTML elements that Editor operates on are controlled by two data attributes:

  • data-editor-field - The value of this attribute tells Editor that the content of this element is to be used for the Editor field of the same name.
  • data-editor-label - Optional. If defined, Editor will use the content of this element as the label for the field. This is useful if the label is already in the HTML, so you don't need to specify a fields.label option for the field.

The edit action is triggered by calling the edit() API method when a click is detected on a button element.

The example shown here has a dl list of items which could be configured from a server. Please note that the data is not saved on the server-side for this example and a refresh will reset the data.

For further information about using Editor in standalone mode, please refer to the Editor manual.

State:
Enabled
Server IP:
153.63.213.41
Poll period:
60 seconds
Protocol:
TCP
  • Javascript
  • HTML
  • CSS
  • Ajax
  • Server-side script
  • Comments

The Javascript shown below is used to initialise the table shown in this example:

var editor = new DataTable.Editor({ ajax: '../php/standalone.php', fields: [ { label: 'Status:', name: 'enable', type: 'radio', options: [ { label: 'Enabled', value: 'Enabled' }, { label: 'Disabled', value: 'Disabled' } ] }, { label: 'Server IP address:', name: 'server-ip' }, { label: 'Polling period:', fieldInfo: 'Input value is in seconds', name: 'poll-period' }, { name: 'protocol', // `label` since `data-editor-label` is defined for this field type: 'select', options: [ { label: 'TCP', value: 'TCP' }, { label: 'UDP', value: 'UDP' } ] } ] }); $('#edit').on('click', function () { editor .buttons({ label: 'Save', fn: function () { this.submit(); } }) .edit() .title('Edit'); });
const editor = new DataTable.Editor({ ajax: '../php/standalone.php', fields: [ { label: 'Status:', name: 'enable', type: 'radio', options: [ { label: 'Enabled', value: 'Enabled' }, { label: 'Disabled', value: 'Disabled' } ] }, { label: 'Server IP address:', name: 'server-ip' }, { label: 'Polling period:', fieldInfo: 'Input value is in seconds', name: 'poll-period' }, { name: 'protocol', // `label` since `data-editor-label` is defined for this field type: 'select', options: [ { label: 'TCP', value: 'TCP' }, { label: 'UDP', value: 'UDP' } ] } ] }); document.querySelector('#edit').addEventListener('click', () => { editor .buttons({ label: 'Save', fn: function () { this.submit(); } }) .edit() .title('Edit'); });

In addition to the above code, the following Javascript library files are loaded for use in this example:

    The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:

    This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The additional CSS used is shown below:

    #edit { cursor: pointer; } dl.editor-demo dt { margin-top: 1em; } dl.editor-demo dt:first-child { margin-top: 0; } dl.editor-demo dd { width: 25%; margin-left: 3em; }

    The following CSS library files are loaded for use in this example to provide the styling of the table:

      This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is loaded.

      The script used to perform the server-side interaction for this demo is shown below. This server uses PHP, so the PHP script is shown, however our download packages include the equivalent script for other platforms, including .NET and Node.js. Server-side scripts can be written in any language, using the protocol described in the Editor documentation.

      Other examples