How can I use the excel button to export filtered and unfiltered data? No AJAX in use.
How can I use the excel button to export filtered and unfiltered data? No AJAX in use.
High Level: I have a table that I am filtering, I want export buttons to include ALL data in the table, including what's filtered, including hidden columns.
It feels like all the articles I find are people leveraging AJAX and asking how they export data currently loaded + data that's unloaded. That is NOT my issue, I'm not using AJAX and the data is all encapsulated on the page. My initialization is fairly simple:
var table = $('#table').DataTable({
dom: 'Bfrtip',
"aoColumnDefs": [
{
"aTargets": [0,1,2],
"bVisible": true,
"bSearchable": true
},
{
"aTargets": [3],
"bVisible": false,
"bSearchable": true
},
{
"aTargets": ['_all'],
"bVisible": false,
"bSearchable": false
}
],
buttons: [
'csv', 'excelHtml5', 'pdf', 'print'
]
});
My reading suggests TableTools would do this, but I don't have much interest in the deprecated and replaced tool. Can this be accomplished with Buttons? Hidden columns are included just fine, it's the currently filtered data I can't find a way to include.
Thanks!
This question has an accepted answers - jump to answer
Answers
Still haven't been able to find an answer to this, appreciate any thoughts or pointers.
You can use exportOptions to control what is exported.
https://datatables.net/extensions/buttons/examples/print/columns
Specifically you can use this export option to export all rows regardless of filtering:
Kevin
What Kevin says. Absolutely spot on .
Allan
Works like a charm, thank you! Still not sure where it's documented what all the options related to exportOptions are, maybe it's just the structure of documentation that's throwing me, but even now knowing the answer I'm not able to find it.
Structure of the documentation. The export options are basically defined by
buttons.exportData()
. That object is passed in from theexportOptions
parameter of theexcelHtml5
button type.Each part if technically correct, but they need to overlap more.
Allan