Setting Editor fields dynamically
Setting Editor fields dynamically

Hi,
I have a whole bunch of tables which are almost all dynamically created by the server.
I can get the tables to do what I want, but I can't get the Editor to actually edit. On Delete it sends the right request to the server, but on Edit it just shows an empty form, same on new.
Code and data below:
Any ideas?
function setup_editor(table_selector, params, data_url, editor_url) {
editor = new $.fn.dataTable.Editor({
table: table_selector,
ajax: editor_url,
idSrc: 'id',
});
let my_table = null;
$.post(data_url, params,
function (json) {
if (my_table != null) {
my_table.destroy();
my_table = null;
table_selector.empty();
}
ts = $(table_selector);
my_table = ts.DataTable({
dom: 'Brtip',
data: json.data,
columns: json.columns,
select: true,
rowId: 'id',
buttons: [
{extend: 'create', editor: editor},
{extend: 'edit', editor: editor},
{extend: 'remove', editor: editor}
]
});
editor.fields = json.fields;
});
return editor;
}
The data is coming in format:
data =
[
{
Filter_Name: "year filter",
attr_0: "EQ 2013",
....
id: "id_8839894248792230502"
}
{
...
}
]
columns=
[
{ data: "id", visible: 0},
{ data: "Filter_Name", title: "Filter Name"}
{ data: "attr_0", title: "year"}
{ data: "attr_1", title: "imdb"}
...
]
fields = [
{ data: "id", name: "id", visible: 0 },
{ data: "Filter_Name", label: "Filter Name", name: "Filter_name" },
{ data: "attr_0", label: "year", name: "year" },
{ data: "attr_1", label: "imdb", name: "imdb" }
...
]
This question has an accepted answers - jump to answer
Answers
ok, never mind, looks like I have to set it one by one via the add..
Correct - the
add()
method is the way to handle this.Allan