Excel download with serverside scripts using Buttons
Excel download with serverside scripts using Buttons
I am using Datatables to display data to the users where I am fetching data using serverside scripting. One of the feature I am required to build is excel download which I believe can be achieved by using BUTTONS (previously via table tools which are now depricated). While using buttons I am only able to download the data on display i.e. 10/25/50/100 as selected by the user and not the entire dataset (for example ~1000 rows). Googling has told me that prople have achieved this in the past but using 'oTableTools'. Can someone point me in the right direction to achive my goal using 'BUTTONS'.
Answers
Hi,
sample with more than 1000 rows
http://jsfiddle.net/ebRXw/724/
export only the current page is not the default behaviour.. so maybe u are using this?
exportOptions: {
modifier: {
page: 'current'
}
}
Hi Thorsten,
Many thanks for your quick reply. I am using serverside scripting and that only has 10 rows. I am not using the
exportOptions: { modifier: { page: 'current' } }
option. I have hardcoded 'var dataSet' to contain a few rows from your example just to see if I can overwrite the data but it still exports only 10 rows (that are on table's display).my table init code looks like below
A quick point about my code above, Line 3
data: dataSet,
should be removed. I only added this to try your suggestion, else we are giving 2 data sources i.e. other one is on line 13 onwards 'ajax:' which is what I wish to use for entire dataset download as excel.Thanks,
Ebad
I am not using .php so i cant tell you if there is something wrong in your php code. But i can show you the way i am using the datatable and his buttons. Maybe it helps.
GetSampleData is an WebApiController-Method which return and
IEnumarable<SampleDataDto>.
SampleDataDto looks exactly like the Columndefinition
Hi Thorsten, thanks.
Q1- Does GetSampleData contain all the records (~1000 e.g.) in it and this get paginated by datatables?? In my case server_processing.php only returns 10 rows which is returned as json. If I remove my limit it gets really slow while returning everything and still paginates.
Q2- Are we expecting to make a subsequent call to the server side script upon user click on the 'Excel' (file download) button. Looking at the code I understand that we are only exporting whatever we have at the client and no call is made.
Hi,
Q1: Yes.
Q2: I am not sure about that but i think this is exactly your problem. seems like youre are loading data on demand? what happens if u click some pages first and than hit the export button, does he still only export 10 rows or 10xPages clicked?
buttons.exportData()
this function is used by the excel export