I want to use Editor extension in my vue 3 project. How do I use it?
I want to use Editor extension in my vue 3 project. How do I use it?
chita
Posts: 33Questions: 12Answers: 2
I want to use editor, one of the extension features of datatable, in my vue 3 project. However, all the descriptions or examples on the official page are based on jquery and do not have any descriptions related to vue. I've tried many ways, but they all failed. So I want to know how to use editor in vue 3 project.
This question has accepted answers - jump to:
Answers
Hi,
Have you seen this example which, while it doesn't show Editor, it does how the Vue component we publish for DataTables and use of extensions such as Buttons.
Using Editor in Vue would be done in exactly the same way. npm install Editor and then import it and use it in the same way as the examples on this site - e.g.:
Let me know how you get on with it.
I'll look at adding an example on our site for that.
Regards,
Allan
I set up the code as above and installed editor, but the error TypeError: DataTable.Editor is not a constructor appears in the Web Administrator tool. Is there an example of actually using editor to add features to the data table?
There isn't an example of Vue with Editor yet. As I noted I need to look into doing that.
Try:
then
Editor should attach itself to the DataTable object so I'm not sure what is going wrong there, but it will return itself, so my suggestion here should do the job.
From your other thread it sounds like you want to make changes to the table's data without an Ajax submit. Is that correct? If so, have a look at this example which shows how to do that (not Vue based, but the key is simply that the
ajax
option isn't given - that would apply for using it in Vue as well).Allan
The above-mentioned error continues to occur. The current <script> situation. What's the problem?
Is the above code not available in the .vue file?
If you change:
to:
I think that should address it.
Allan
The existing error is gone, but a new error called Uncaught (inpromise) TypeError: DataTable is not a constructor...
Doh - I was forgetting how the Vue component works. You use the
<DataTable>
component in the template, not as a constructor. Try this:Allan
Wow! The table is showing normally using the above code! Thank you so much!! Excuse me, but may I ask you one more question? How do I use the inline editing function in the code above? I'm explaining it in that example, but I don't know how to add it.
You need a reference to the DataTables API instance for the table. you can get that as described in the manual here. There is an example linked there too.
Then, use
where
table
is the API reference.Allan
The current state of <script> is like this, and this will result in the error Uncaught (in prompt) TypeError: table.on is not a function.
With that code you DataTable API instance is the variable
dt
:You would use
dt.on(...)
.This example shows the API being used.
Allan