Reputation: 418
In my project, based on Datatables+YADCF, works with more dropdowns and Select2 fields. All data are loaded with Ajax requests. Okay, and question:
Is possible set default selected values in Select2 field after select value in dropdown?
Or another question: Is possible autofill selected values in select2 field only with Ajax data?
(maybe:
{
key: 1,
value: car,
default: true
}
UPDATE
(Server is hosted on heroku (free plan - can be sleep after 30 min of inactivity). Server side is is not ideal, but for this example is probably okay.)
Here is first example:
Basic using of Datatables + YADCF library. Above of first column are names in dropdown element. In select2 above of second column are surnames. After selecting "name" in dropdown are filtered "surnames" in 2nd column.
https://jsfiddle.net/lukassliacky/fojp91zx/
2nd example:
Surname "Winters" is prefilled after run example:
https://jsfiddle.net/lukassliacky/fojp91zx/6/
Okay, and question:
In 2nd example are surnames prefilled after refresh with external API function:
yadcf.exFilterColumn(oTable, [[1, ['Winters']]])
Please, is possible load this "prefilled surnames" from server after every request?
For example: I have countries in dropdown and i need load and prefill regions of selected country in select2 field.
Thank you for you answer.
Upvotes: 0
Views: 1455
Reputation: 37061
You should use the yadcf.exFilterColumn
method, see example
yadcf.exFilterColumn(oTable, [
[0, ['Some Data 1', 'Some Data 2']]
]);
for pre filtering multi select filter you should use array with values (or an array with single value)
Upvotes: 1