Field type select does not load ajax option when editor is not associate with a datatable
Field type select does not load ajax option when editor is not associate with a datatable
domus71
Posts: 5Questions: 0Answers: 0
Here, it's an example that does not work (the select field is not populated from AJAX response):
piHistory = new $.fn.dataTable.Editor( {
ajax: "/api/paperinventory/history",
fields: [ {
label: "field1:",
name: "ph_date",
type: "datetime"
}, {
label: "User:",
name: "ph_user_id",
type: "select",
placeholder: "-Select-"
}
]
} );
If the editor is associated with a table, everything seems to be ok:
piHistory = new $.fn.dataTable.Editor( {
ajax: "/api/paperinventory/history",
table: "#datatable1",
fields: [ {
label: "field1:",
name: "ph_date",
type: "datetime"
}, {
label: "User:",
name: "ph_user_id",
type: "select",
placeholder: "-Select-"
}
]
} );
I don't have a table to associate the editor. Any ideas or workarounds?
Thanks,
Costis
Replies
The Ajax response ("/api/paperinventory/history")
{"cancelled":[],"data":[],"fieldErrors":[],"files":{},"options":{"ph_user_id":[{"label":"User 1","value":184},{"label":"User 2","value":188},{"label":"User 3","value":191}]}}
That is correct - Editor's options initialise on DataTables
xhr
event. Without a table that event doesn't happen, thus it can't see those options. Moreover, Editor doesn't make an Ajax request when initialising, only when submitting the data.What I would expect to happen with the above is if you submit the row (and it were accepted) then the options returned would at that point be populated for the next row.
What you would need to do in this case is make an Ajax request to get the options for the select field, or if you already have them, include them using the
options
parameter for the object.Allan
Great! I have already done that. Targeting the initCreate & initEdit events, I update the options field.
Thanks