select2 dataTables Editor Plugin
select2 dataTables Editor Plugin
Denis.David@dqs.de
Posts: 28Questions: 8Answers: 1
in Plug-ins
Is there a way to support select2 tags option (together with the multiple option) with the dataTables select2 plugin, to let the user dynamically add custom options?
Using select datatype and initializing the input field with select2() constructor after editor popup, the GUI perfectly allows to add custom tags but they are not saved after posting the input.
This discussion has been closed.
Answers
Hi,
Sorry for the delay in replying here. Yes, this can be done, you just need to add the
attr
option to the field configuration, which allows you to specify HTML attributes for theselect
element, including themultiple
attribute. E.g.:Regards,
Allan
Hi Allan,
Thanks for your reply.
Unfortunately this does only work with the standard "select" data type but not with "select2". Multiple choices from the given Options list are selectable and get successfully saved but manually added tags are discarded after saving them.
Any other ideas?
Thanks,
Denis
Are the manually given options submitted to the server? Is this a join table and you are looking to have new options added to the joined table?
Allan
I am using a DOM only table.
Here is a snippet from my ajax function to save new records:
If you add a
console.log( d.data );
at the top of your local ajax function, does it contain the additional new values when you submit then from an edit action?Allan
No, it doesn't. Only the value selected from the given option list.
Anyway, before saving, the additional (manual) entry is correctly shown as selected item in the select field.
Okay - that limits where we need to look. If there data isn't being given by Select2, then we need to discover why that is.
I'm wondering if it might be because the
tags
option isn't specified. WHat happens if you use:Allan
I already checked this, the tags flag is set.
Any other idea what I could look for?
Sorry for the delay - I'm going to try and set up a local test case to see what is happening here.
Allan
Hi Allan,
Could you reproduce the effect on your side? Do you need any further detail information?
Using the above code, if I type into the select2 input area and then press return it creates the new tag automatically. Then submitting the Editor form I can see that data being submitted to the server:
(the second term above was the one I entered).
Could you give me some details on how I create a demo of this locally, or better yet would be if you could link to a page that demonstrates the issue so I can debug it directly.
Thanks,
Allan
Could it be somehow related to this issue:
https://datatables.net/forums/discussion/29913/select2-4-0-0-ajax
Obviously there has not been any final official solution to this.
In the editor.select2 plugin code I successfully changed the get() method, so selected option(s) are correctly saved into datatable now. The remaining issue is that the value(s) dont get into the select2 field back when opening the edit mask.
Here is my modified get() code:
I tried the modified set() code in the posting mentioned above by unfortunately with no success.
Thanks for your help,
Denis
Hi Denis,
Sorry for the delay in replying here. It is possible that it is related to Select 4.0.0, but I know that a number of people use Select 4 successfully with Editor so I'm not sure exactly what is going wrong here.
If you could provide a link to the page that would really help with resolving this so I can debug it directly. At the moment I've not been able to recreate the issue.
Thanks,
Allan