Editor example Field types

When working with forms you don't want to be limited to just text input fields - HTML forms provide a lot of input options such as radio buttons, checkboxes etc, and Editor makes it easy to configure and use these input types with an editable DataTable through the fields.type option for field definitions.

Each field type provides its own options for configuration and user interaction methods. The three types used in this example are text (the default), select and radio. The select and radio options are configured through their options options array, which defines the options for the fields, as shown in the example below.

The field types that are built into Editor are documented on the Editor web-site and additional types can be added through the use of field type plug-ins.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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/todo.php",
        table: "#example",
        fields: [ {
                label: "Item:",
                name:  "item"
            }, {
                label: "Status:",
                name:  "done",
                type:  "radio",
                options: [
                    { label: "To do", value: 0 },
                    { label: "Done",  value: 1 }
                ],
                def: 0
            }, {
                label: "Priority:",
                name:  "priority",
                type:  "select",
                options: [
                    { label: "1 (highest)", value: "1" },
                    { label: "2",           value: "2" },
                    { label: "3",           value: "3" },
                    { label: "4",           value: "4" },
                    { label: "5 (lowest)",  value: "5" }
                ]
            }
        ]
    } );
 
    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: "../php/todo.php",
        columns: [
            { data: "priority", className: "dt-body-center" },
            { data: "item" },
            {
                "data": "done",
                "render": function (val, type, row) {
                    return val == 0 ? "To do" : "Done";
                }
            }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );

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