Refresh options values in Editor
Refresh options values in Editor
igorl
Posts: 3Questions: 2Answers: 0
Hello,
I'm trying to refresh options used in Editor select fields, but without success. I'm able to set it on initialization time to a fixed list.
Below is my failed attempt. I need to run an ajax query to retrieve the list of options and looks like by the time I get the response, Editor is already initialized and this has no effect.
var usersGroups = [];
var editor = new $.fn.dataTable.Editor({
table: '#Permissions',
fields: [
{
"label": "User \/ Group:",
"name": "user_group",
"type": "select",
"options": usersGroups,
"def": function () {
var reqUrl = "./users";
$.getJSON(reqUrl, function (data) {
usersGroups = [];
$.each(data, function (i, value) {
usersGroups.push(value.user_name);
});
}).done(function () {
console.log("ok");
}).fail(function () {
console.log("error");
}).always(function () {
console.log("complete");
});
}
}
Any ideas how to solve this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You need to use
field().update()
to update the list of options. The problem with the above is thatuserGroups
is only populated after Editor has already populated the fields since it is asynchronous.I'd suggest not using
def
and instead doing:Allan
Works perfectly! Thank you.