Data export buttons are not showing on screen
Data export buttons are not showing on screen
denisPF
Posts: 13Questions: 3Answers: 0
Hello colleagues,
I'm using Datatables.net in a vue js application. I'm trying to insert the option to export table data in pdf and csv, however, the way I'm doing it, the buttons to export the data are not being displayed on the screen.
The snippet of code where I insert the buttons is this:
$('#tb_dadosrecentes').DataTable({
data: data,
language: {
emptyTable: 'Nenhum resultado foi encontrado para essa requisição.',
},
destroy: true,
paging: true,
searching: true,
processing: true,
dom: 'Bfrtip',
buttons: ['copy', 'csv', 'pdf', 'excel', 'print'],
columnDefs: [
and the section where I import the components is the following:
import "datatables.net-dt/js/dataTables.dataTables";
import "datatables.net-dt/css/jquery.dataTables.min.css";
import "datatables.net-buttons/js/dataTables.buttons.js";
import "datatables.net-buttons/js/buttons.colVis.js";
import "datatables.net-buttons/js/buttons.flash.js";
import "datatables.net-buttons/js/buttons.html5.js";
import "datatables.net-buttons/js/buttons.print.js";
import 'datatables.net-buttons';
import 'datatables.net-buttons-dt';
Could someone help me identify what I'm doing wrong or what I'm missing?
att,
Adenilson
Answers
Excel export needs JSZip and PDF export needs pdfmake (i.e. two additional external libraries). Also remove the buttons.flash.js - that's no longer supported.
Since you are using Vue, you might want to consider using our Vue component for DataTables.
Here is an example of our Vue component used with export buttons.
Allan
Hi Allan,
Thanks for the tips but I wouldn't want to use a new component just the ones that already exist and are even more common. Besides, I'm already importing these two components in my code:
I already removed the flash.js component but still no button is showing on the screen.
regards,
Adenilson
I forgot to mention that I'm using axios, as per the code snippet below, to fetch the data via web services:
I'll need a test case showing the issue in that case please. Did you add:
like in the example I linked to? That isn't specific to our Vue component.
DataTablesLib
there is thedatatables.net
import.Allan
Hi again Allan,
I think it was to be easier to include these buttons in the code but it isn't...
I left it exactly like your example including the imports but the error below is appearing:
and the snippet that initializes the table and inserts the buttons looks like this:
Strange because the approach proposed in the post https://datatables.net/extensions/buttons/examples/initialisation/simple.html below isn't working either.
Could someone help me on this?
Att,
Adenilson
Allan asked you to provide a test case.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
The example in the page you linked to is just using UMD loaders to bring the libraries in globally. However, Vue generally doesn't work that way, which is why I created a DataTables specific Vue extension.
As tangerine notes, I'd really need a test case to be able to debug this, as there are so many possibilities for what is going wrong.
Allan
Hi Tangerines,
I don't know how to provide a test case because my vue 3 code is very complex and I can't separate it into HTML, JS and CSS.
There are many imports and interdependencies.
What I could provide would be the .vue file that contains the part referring to the <Template>, the Script and the CSS of the page in question.
But i don't know if this would help in any way?
This is the content of the .vue File (without Template and style sections):
Att,
Adenilson
Ah, you are using the DataTables Vue component. That certainly helps to clarify that point.
That said, I don't see anything wrong with the above code. It is very similar to the Stackblitz example I linked to before.
Can you link to the resulting page please? I really would need to be able to see it given that the example that I can see is working.
Allan