Buttons icon indicating copy to clipboard operation
Buttons copied to clipboard

Customize Data Before Export; HTML5 & Flash Buttons (e.g, copy, CSV, Excel, PDF) and Print button

Open vol7ron opened this issue 9 years ago • 10 comments

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

vol7ron avatar Mar 05 '16 03:03 vol7ron

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>

vol7ron avatar Mar 05 '16 19:03 vol7ron

Thanks for posting this! I'll try to find some time later this week to review it closely.

DataTables avatar Mar 07 '16 09:03 DataTables

Really nice. Thanks a lot...

Thassya avatar Mar 07 '16 16:03 Thassya

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.

vol7ron avatar Mar 09 '16 06:03 vol7ron

And, after one year, where is it?

jeshio avatar Feb 15 '17 06:02 jeshio

Any updates about this feature?

fanckush avatar Mar 07 '17 12:03 fanckush

Sorry - this slipped by me with everything else going on. I will try to look at it soon.

DataTables avatar Mar 07 '17 15:03 DataTables

I'd hoped to get it done for the 1.3 release, but its going to drop into 1.4 now I'm afraid.

DataTables avatar Apr 18 '17 15:04 DataTables

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 avatar Jul 15 '20 13:07 bbrindza

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.

vol7ron avatar Oct 21 '20 17:10 vol7ron

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.

AllanJard avatar Oct 17 '23 14:10 AllanJard