How to export all data with HTML5 export buttons, when using AJAX as a datasource.
How to export all data with HTML5 export buttons, when using AJAX as a datasource.
topiker
Posts: 1Questions: 1Answers: 0
Hello,
I am using HTML5 export buttons. I am using AJAX as a datasource, which returns only the required data for current page. The problem is, that I want to export all data, not only current page. Is it possible?
PS: Export works good but it only exports current page.
Here is configuration:
var table = $('#zadosti').DataTable({
searchDelay: 2000,
processing: false,
serverSide: true,
ajax: {
url: instance.DataTableSourceURL,
type: "POST",
-----
some code
-----
buttons: [
{
extend: 'pdfHtml5',
text: 'PDF',
title: 'Requests',
exportOptions: {
"columns": ':visible',
}
},
This discussion has been closed.
Answers
topiker, I'm having the same issue.
Now I'm reading that this is part of serverside processing - the current page of data is all that's available when trying to export. Now I'm investigating client-side rendering while only displaying some records.
This is the issue. The file export is client-side, but if you are using server-side processing then the data available at the client-side is only that which is currently displayed (that is the whole point of server-side processing - only a limited sub-set is available at the client-side).
If you want to export the full data set, you would need to either:
Allan
Just curious... How many rows are you expecting to be exported? (Just ballpark it)
(In my opinion), if you're using the
serverSide
option, then overall, you're playing around with more rows than you would want to export.. I would think it would be best to play around with thelengthMenu
, giving the viewers limits of how much they can export, then allow them to filter for the relevant data they want to export viasearch
... EG: If they want to export all rows containing "Some Data", then set the page length to the highest you would let it go (100, 200?), then filter for "Some Data", and export that.topiker, I solved my similar problem by simply adding a -1 option to the dropdown of the paging options. That allows me to select all records (it takes a while to display, true) so then the Excel export button exports all records, since they're all displayed. I had to modify a LIMIT statement in my DB grab in my PHP so it would do the right thing when it received a -1.
@kwein1 May as well not even use
serverSide
Agreed - if you are going to just load all the data to the client-side anyway, I don't see any benefit of using server-side processing. In fact it will just hurt performance due to the latency it introduces.
Allan
As I said in the other thread, and ill re-state it for @topiker