Autocomplete/Select2 with Vue
Autocomplete/Select2 with Vue
ktadrowski
Posts: 13Questions: 5Answers: 0
Hello,
I need functionality like autocomplete for my Vue 3 + Datatables + Editor
While searching through the forum I came across Autocomplete and Select2 plugin for jQuery.
How can I use them with Vue?
They individually offers npm libraries, but will datatables and eventually Editor can detect those and enable the field as autocompleting dropdown?
-Thanks.
Answers
At the moment, what you would probably need to do in this case is use the code from the Editor / Select2 integration file (possibly without the UMD if you are using ESM loaders), which will attach itself to the
DataTable
object and you'd then be able to usetype: 'select2'
as normal from there.I do intend to provide NPM modules for the plug-ins to make this kind of thing a little easier in future, although I'm not yet certain when that will happen (I'm working on the code Editor library as an NPM package at the moment).
Allan
Hey Allan,
Thanks. I have done following till now:
In index.html included:
In my vue project I have added the integration file >! "editor.select2.js" and removed the AMD related "if condition". The contents of factory function looks like this now:
Then I imported "editor.select2.js" in my component as below:
Later tried to add the field type to editor config as:
and also tried to add it in onMounted() as:
But I am still getting error:
Do you know if you are using CommonJS or ESM?
If ESM (which is reasonably likely with Vue), you'll probably need to do:
at the top of the integration file. That will populate the
DataTable
variable and give somewhere for the plug-in to latch onto.Allan
ESM it is.
I modified the import as below:
and that removed the type error.
I have also replaced the require('datatables') with require('datatables.net-vue3'), the correct library name for Vue.
Now below console.log statement coming as undefined
it's undefined, and so the error turned as
I tried to remove the DataTable as function parameter, which resulted into displaying the DataTable object in console, but that object is also missing