custom button to download all the data serverside
custom button to download all the data serverside
![_mercury](https://secure.gravatar.com/avatar/ab9b735bb9a9cd2bec4c261c9a2b0f8b/?default=https%3A%2F%2Fvanillicon.com%2Fab9b735bb9a9cd2bec4c261c9a2b0f8b_200.png&rating=g&size=120)
how could i send a request like the same request sent by ( show all ) by a custom button , i prepared the server to respond by the csv file .. but i need a way to send a get request ( not by ajax ) by the same lonk that showcnall send ?
Answers
Documentation on how to create a custom button is available here.
If you don't want to use Ajax, you'd need to create a form and submit it. You can absolutely do that in a custom button (since it is just callback function, so you can execute any Javascript you want).
Allan
But how to get the link to the send to? ..
The ( show all ) link represent the current state?
I would say that you need to create a link in your server to use that calls your function to create the CSV file. Then use that link in the custom button. There is nothing within Datatables to derive the link.
Kevin
Yes I did that on the server by** show all** button, but since it is a show all button .. datatables gives an error because it wants data, not CSV, also it is an ajax request which does not allow to download CSV file.
so if I could know how to get the ( show all ) link and add it to the custom button ( 'I know how to create a custom button ) but I need the link because that link preserves the table state ( filters ... etc ).
Or any other solution to the whole problem
How to tell the backend ( the state of the table is like so ) and I want this data only !!
I found the ( show all ) link is telling everything but how to get the link is not obvious for me !
I'm not sure what your Show All button is doing. Can you post the code?
This SO thread has some options for downloading a CSV and saving to a local file. Maybe one of those would work.
You can use the
search()
,order()
andcolumns().search()
APIs to get the state of the table to send as parameters.Kevin
I just want to know how show all button generate the link to simulate that
Is this a button you currently have? If so please post the code for the button.
Kevin
Calling
ajax.reload()
isn't going to generate a CSV file (it will reload the data in the DataTable).You could do something like:
and have that route on the server respond with a CSV file, which the browser can the download or display (depending on the MIME type and the browser's settings).
If you need to pass information about the DataTable's state to the server, you can use
state()
to get the current state, and then add it as query parameters to your url.Allan
thx alian
how to convert the state to a link to be exact like show all link?
Do you mean how to show the button as a link tag? If so, see this thread which is asking the same thing. You'll need to apply some custom styling if you want it to look like a regular link rather than a button.
Alternatively, just do:
which sounds like basically the same thing - i.e. a custom link and have it be an
a
tag.Allan