How to fill a select2 from a table
How to fill a select2 from a table
rrojas2018
Posts: 8Questions: 3Answers: 0
I need your help please I have the select2 working with static data, but I can not fill it with data from my table, in this tablei need concat the code+name, to show in select
This discussion has been closed.
Replies
Your code would be helpful but I try without it:
a) Javascript field instance (I use selectize but select2 isn't much of a difference):
b) PHP from the Editor instance:
As you can see you can concatenate as many fields as you like on the server side. You can even join multiple tables with the ->options method. But LEFTJOIN does not work in -> options hence I needed to use an old fashioned 1990's style join through the WHERE clause mentioning both tables in the ->table instance. In addition the ->options method only accepts WHERE clauses as closure functions.
Thanks rf1234, your code helps me understand many things but the reason I want to use select2, is because I need the search through autocomplete, I'm not sure if the selectize allows you to do that?
Selectize also has autocomplete. But keep using Select2. It should work as well. The rendering is done on the server side anyway regardless of what you use on the front end.
I don't use Select2 because you can't limit the number of options read. In my case it is over 10,000 read from a database which causes performance issues on the front end. Selectize allows me to limit the number of options presented.
The link to the seletize plug-in for Editor: https://editor.datatables.net/plug-ins/field-type/editor.selectize
More details regarding selectize usage: https://github.com/selectize/selectize.js/blob/master/docs/usage.md
Great I must say that I missed adding the plugin files is exactly what I needed many thanks rf1234