How to add an export button to a table in excel that was generated dynamically?
How to add an export button to a table in excel that was generated dynamically?
Hi all! I found a good example that helped me add a button to export a spreadsheet to excel. But it only works when the data is already in HTML and after that DataTable is initialized. Here's how it happened:
$("#example1").DataTable({
"responsive": true,
"lengthChange": true,
"autoWidth": false,
"pageLength": 100,
"order": [],
// buttons: ["copy", "pdf", 'excel', "colvis"],
buttons: ["copy", {
extend: 'excel',
exportOptions: {
columns: ':visible'
},
title: ''
}, "colvis"],
"language": dataTableLanguage,
}).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
Works great for data that is already formed.
But how can I do the same for the data that I dynamically get through an Ajax request and then do a draw()?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
I don't think our Buttons examples actually have an Ajax sourced example, but Editor does have an export button example with Ajax sourced data.
As you will see there the export works just fine with Ajax sourced data.
If it isn't working for you, please provide a link to a page showing the issue so we can help to diagnose and resolve the issue, per the forum rules.
Allan
@allan Thanks a lot! Happened!