Editor example Inline editing

This example is basically the same as the simple standalone editing example but in this case the inline() method is used for editing the fields, rather than the edit() primary method for editing the whole form.

Standalone forms can befit from inline editing in exactly the same way as DataTables based editing forms and with all of the same features. As with DataTables, this can be very beneficial for speed of editing.

Please note that this example doesn't actually save to a database at the server. A refresh will result in the original values being restored.

State:
Enabled
Server IP:
153.63.213.41
Poll period (seconds):
60
Protocol:
TCP

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' } ] } ] }); $('[data-editor-field]').on('click', function (e) { editor.inline(this, { buttons: '_basic' }); });
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.querySelectorAll('[data-editor-field]').forEach((el) => { el.addEventListener('click', (e) => { editor.inline(e.currentTarget, { buttons: '_basic' }); }); });

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; } *[data-editor-field] { border: 1px dashed #ccc; padding: 0.5em; margin: 0.5em; } *[data-editor-field]:hover { border: 1px dashed #333; } html.dark *[data-editor-field] { border: 1px dashed rgba(255, 255, 255, 0.15); } html.dark *[data-editor-field]:hover { border: 1px dashed rgba(255, 255, 255, 0.25); }

    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 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.