select2 plugin and default values in Editor
select2 plugin and default values in Editor
Hi
What's the recommended method for loading in default values into a select2 field Editor? I'm using multiple attr and I can create a new row and save data to remote server but when I edit a row I am unable to load the select2 field with the datatables column's values. I currently am rendering this column as a comma separated list of values, ie "1,2,3,..".
The select2 documentation suggests adding a selected option for each value (https://select2.github.io/examples.html#data-ajax). I've also seen a possible method $myselect2.val("2").trigger("change") that might work although I'm not sure if I'd need to use inst() method to call this. Perhaps there's another way?
Also, how can I render a select2 column in DataTables itself? A bit like the Tags column here (http://yadcf-showcase.appspot.com/DOM_source_select2.html).
Thanks for any help in advance
Blair
Answers
I resolved the issue by setting the column value to an array of dictionaries, ie,
then patching the select2 plugin get method like so:
Admittedly not the nicest code. Finally for the column render I did this:
Hope this might help someone else in future.
I'm able to use the select2 plugin using value/label pairs for the columns. I did not make changes to the plugin.
Here is an example Editor field:
The corresponding Datatables column:
My device_types object looks like this:
I get the default selections and can add and delete as needed.
Kevin
Thanks @kthorngren. I think the difference might be that I am using a remote data source with paging for my select2. So the labels do not already exist in memory and cannot be selected from a list of ids. Please correct me if I'm wrong. ie