Changing simple join example to use local table editing causes errors
Changing simple join example to use local table editing causes errors
Hi,
I am trying to utilise Local Table Editing on the Editor example for a simple join.
I excluded the ajax option as per the example code but when I try to edit the Location field which is the joined field, the DataTable table does not display the new value. The Editor screen however does show the new value.
If I add a new row, a message appears saying "DataTables warning: table id=example - Requested unknown parameter 'sites.name' for row 37, column 3. For more information about this error, please see http://datatables.net/tn/4"
Please could you point me in the right direction?
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
// ajax: "/api/join",
table: "#example",
fields: [ {
label: "First name:",
name: "users.first_name"
}, {
label: "Last name:",
name: "users.last_name"
}, {
label: "Phone #:",
name: "users.phone"
}, {
label: "Site:",
name: "users.site",
type: "select",
placeholder: "Select a location"
}
]
} );
$('#example').DataTable( {
dom: "Bfrtip",
ajax: {
url: "/api/join",
type: 'POST'
},
columns: [
{ data: "users.first_name" },
{ data: "users.last_name" },
{ data: "users.phone" },
{ data: "sites.name" }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
} );
Replies
I've put together this example showing how to do local table editing with joined data. The key issue is that you need to have both the value and label in the data source for the row (or some other way of looking up the label from the value).
Allan