Populate Datatables Editor Select2 Options from Web API
Populate Datatables Editor Select2 Options from Web API
jacktrap
Posts: 14Questions: 6Answers: 0
I have a javascript function that returns label + value array for my select2 list. The function and it's output are as below:
function GetEtms() {
var actionUrl =
'@Url.RouteUrl("DefaultApi", new {httproute = "", controller = "VariableAdditionAdmin", action = "GetEtMs"})';
$.getJSON(actionUrl,
function(response) {
if (response !== null) {
return response;
}
});
};
Output (just dummy data for now) :
[{"label":"Please Select","value":"0"},{"label":"Some Selection Label","value":"1"}]
How do I have my datatables editor field Select2 list use this javascript function to populate?
{
label: "ETM:",
name: "EtmId",
type: "select2",
"opts": {
"allowClear": true
}
},
Previously when I was using a regular dropdown I used the below (this no longer works now i'm using select2) :
function updateEtmDropdown() {
var actionUrl =
'@Url.RouteUrl("DefaultApi", new {httproute = "", controller = "VariableAdditionAdmin", action = "GetEtMs"})';
$.getJSON(actionUrl,
function(response) {
if (response !== null) {
editor.field('EtmId').update(response);
}
});
};
updateEtmDropdown();
I have included the select2 datatables plugin in my project.
This discussion has been closed.
Answers
Nevermind, was all in the select2 documentation.
Where q is the search term. Searching done serverside.