# Editor example 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

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

`var editor = new DataTable.Editor({ ajax: '../../controllers/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(); });`
`const editor = new DataTable.Editor({ ajax: '../../controllers/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(); });`

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

- https://code.jquery.com/jquery-3.7.0.js
- https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js
- ../../js/dataTables.editor.min.js

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:

`dt { margin-top: 1em; } dt:first-child { margin-top: 0; } dd { width: 25% }`

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

- https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css
- ../../css/editor.dataTables.min.css

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 processing for this table is shown below. Please note that this is just an example script using PHP. Server-side processing scripts can be written in any language, using the protocol described in the DataTables documentation.