Editor example Simple standalone editing

Editor's primary use is as an Editor for DataTables, however, it can also be used as 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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var editor; // use a global for the submit and return data rendering in the examples
 
$(document).ready(function() {
    editor = new $.fn.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();
    } );
} );

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

Editor submits and retrieves information by Ajax requests. The two blocks below show the data that Editor submits and receives, to and from the server. This is updated live as you interact with Editor so you can see what is submitted.

Submitted data:

The following shows the data that has been submitted to the server when a request is made to add, edit or delete data from the table.

1
// No data yet submitted

Server response:

The following shows the data that has been returned by the server in response to the data submitted on the left and is then acted upon.

1
// No data yet received