Customize Data Before Export; HTML5 & Flash Buttons (e.g, copy, CSV, Excel, PDF) and Print button
I posed a question here: http://datatables.net/forums/discussion/comment/89936
This talked about how the whole data set could not be customized before output, only formatted row-by-row, excluding the possibility of dynamic subtotals.
A person could create their own buttons, but sometimes they may not want to deal with the MIME types, etc.
Please refer to the commit log, and see here for an example of all the buttons working: http://live.datatables.net/sajaxota/6/edit?js,output
Note:
This may not be the best approach, but can be used for a minor version update, until some more thought can be given to a major version change. For instance, one alternative would be to expose a cloned version of the source data to the drawCallback, which would allow the user to modify a dataset for export, without altering the source data.
Thinking further, a user should be able to add classes or data-* attributes to the HTML, which DataTables (or Buttons) would check for and modify the export data automatically. For instance, <tr data-datatables-include="csv">...</...> or <tr class="subtotoal csv-include">...</tr>
Thanks for posting this! I'll try to find some time later this week to review it closely.
Really nice. Thanks a lot...
The most recent commit includes Flash button support and the one before that, includes Excel support. However, I have not tested either thoroughly. Looking at it, it should work.
I glanced at the PDF code and it seems to be getting a width from the HTML. Perhaps in the docs, we should also mention that. If a person does customize their table with new fields/columns, then it's possible the data will be truncated in the PDF document. At this point in time, I suggest baby steps to include these updates as a minor revision and to add potential issues/features to the backlog.
And, after one year, where is it?
Any updates about this feature?
Sorry - this slipped by me with everything else going on. I will try to look at it soon.
I'd hoped to get it done for the 1.3 release, but its going to drop into 1.4 now I'm afraid.
vol7ron, I used your BIN example in one of my tables and it worked as expected. Wonderful code, however I am running into a problem with rowGroup when the printed output is rendered. It is including the rowGroup rows in the $row.index count , which will not line up my subtotal data under the correct group in the print out. Would you have any suggestions?
vol7ron, I used your BIN example in one of my tables and it worked as expected. Wonderful code, however I am running into a problem with rowGroup when the printed output is rendered. It is including the rowGroup rows in the $row.index count , which will not line up my subtotal data under the correct group in the print out. Would you have any suggestions?
@bbrindza sorry for the late follow-up I'm just seeing this now. COVID has kept us all busy to varying capacity. Could you please open up a StackOverflow with an example / screenshot? From the sound of it the subtotal rows are affecting the count and the rendering, but I'm uncertain if I've understood correctly. The counts should be easier to address, but I might require more understanding for the rendering issue.
Epic long bug this :-(. Totally on me that.
The exportData function which is used by all the export buttons has a customizeData callback which can be used to manipulate the data structure for export, including totals and the like. I can't recall if that was inspired by this bug or what, I think the base request here is possible in the latest versions of buttons.