Button export csvHtml5 - skip download
Button export csvHtml5 - skip download
Hi,
I want to send the CSV data to the server and not download it
i am using the following export settings.
! exportOptions: {
! modifier: {
! search: 'applied',
! page : 'all'
! },
! columns: ':not(:first-child)',
! columns: ':visible'
! },
! extension: '.csv',
! fieldSeparator: ';',
How do I prevent only the download?
Answers
You can create a custom button to get teh table data and send to the server via jQuery ajax(). Use
tows().data()
with therow-selector
of{ search: "applied" }
, ie,dt.rows( { search: "applied" } ).data()
in the customer button function. You may need to usetoArray()
to convert therows().data()
result to a Javascript array before sending it via jQuery ajax().Kevin
Thanks,
can i use the other options too?
I want the same result using csv-Export config
modifier: {
page : 'all'
},
columns: ':not(:first-child)',
columns: ':visible'
Sorry I gave the wrong doc link for
{ search: "applied" }
. See theselector-modifier
docs. It also shows the default is{ page : 'all' }
.The
rows()
API doesn't support an option to supply which columns to return.modifier: You have defined thecolumns
option twice. One will overwrite the other so only one of the options will be applied. Code will need to be written to take therows().data()
results and copy the appropriate columns to a new array. I provided an example:https://live.datatables.net/yakeyasu/1/edit
It uses
columns().visible()
to get an array of booleans with the column visibility. It usescolumns().title()
(only in Datatables 2.0) to get the header titles. It usesrows().every()
with theselector-modifier
of{ search: 'applied' }
to loop through all the searched rows. This code is used to keep only the visible columns and not the first column.The
visibleData
result can then be sent via ajax to the server.Kevin
Kevin, many thanks that saves me a lot of time!
Perhaps you have a solution (< DT 2.0) to determine the column related header titles?
I am currently still using the last DT 1.x version
i found a solution for the header titles