Export all regardless of pagination
Export all regardless of pagination
I've searched and searched for this, but can't seem to find a straightforward answer -
I have a collection of export buttons that looks like this:
buttons: [{
extend: 'collection',
className: 'exportButton',
text: 'Data Export',
buttons: ['copy','excel','csv','pdf','print'],
exportOptions: {
modifer: {
page: 'all',
search: 'none'` }
}
}]
What I need is for each of those buttons to export the contents of whatever the table is displaying, regardless of pagination. Currently, if I run a search, and then export with any of those buttons (besides 'print'...oddly) the exported file or clipboard copy only contains the amount of rows as selected in the length dom box.
Is there a way that I can bypass this, and get an export with all matching records of any search?
EDIT: Updated code formatting to use Markdown
This question has an accepted answers - jump to answer
Answers
I believe your exportOptions needs to be inside your
buttons
array to go with each button. For example:Also note you misspelled
modifer
above.Kevin
Thank you for that catch, I wouldn't have caught the typo for a long while
I retooled a bit and came back with this, but it's still only exporting the records currently displayed in the first page of the results (in this case, 25 out of 1675):
buttons: [
{ extend: "create", className: 'newButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
{ extend: "edit", className: 'editButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
{ extend: "remove", className: 'deleteButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
//Options and exports dropdowns
{ extend: 'collection', className: 'optionsButton', text: 'Table Options', buttons: ['colvis'] },
{ extend: 'collection', className: 'exportButton', text: 'Data Export',
buttons: [
{ extend: 'copy', exportOptions: { modifier: { page: 'all', search: 'none' } } },
{ extend: 'excel', exportOptions: { modifier: { page: 'all', search: 'none' } } },
{ extend: 'csv', exportOptions: { modifier: { page: 'all', search: 'none' } } },
{ extend: 'pdf', exportOptions: { modifier: { page: 'all', search: 'none' } } },
{ extend: 'print', exportOptions: { modifier: { page: 'all', search: 'none' } } }
]
}
],
Am I just missing the wrong exportOptions modifier?
If you have server side processing enabled please see the SSP FAQ regarding export buttons.
https://datatables.net/faqs/index
Kevin
Ok, so that answers that - server side processing does not allow for this, that makes sense.
I'm lost on how to create a custom solution, however. If I was to leave SSP on, Is there a method to call in order to fetch and render the extra data based on a custom trigger?
You can use
ajax.params()
to get the parameters that are used for the current server-side processing request (e.g. sorting, filtering information), then use an Ajax request in a custom button that will send those parameters to the server to create the required PDF / CSV file.Allan
Ok, that gives me a starting point
Thanks!
Hai!!. Iam also trying to implement the same. But I would like to know what does 'search:none' within the the modifier option do??. Iam new to datatable.
Hi @sruthirbabu - the documentation for that with an explaination of that value is available here.
Allan
Aún si tienes esta configuración:
Cuando el parámetro
serverSide: true
Sólo descarga por página.
Si pones el parámetro
serverSide: false
o simplemente eliminas ese parámetro, entonces descargará todas las páginas.The simple solution (to me anyway) was to add "all" to lengthMenu:
https://datatables.net/examples/advanced_init/length_menu
Once you refine your search etc. you can change that to "All" the the buttons work just fine and export "all".
Hi, do we have option to export all the data without loading or binding data to dataTable
@Kartiki I'm not sure what that means, or how that relates to this thread. Please can you create a new thread with a test case that demonstrates the issue you want help with,
Colin
he means to load ( all ) data on front-end then download it .. which is not efficient
@_mercury Colin's last comment was over two years ago. Are you having a similar issue?
Allan