How to modify data before export with Buttons API?

How to modify data before export with Buttons API?

c7hc7h Posts: 3Questions: 1Answers: 1

Link to test case: https://live.datatables.net/koyowiso/1/
Description of problem:
I am using the Buttons plugin to export a printable version and an Excel file. For the export I would like to modify the cell content, either the HTML created with

{
  columns: [
    {
       data: function ...
    }
  ]
}

or the original data object. In case of modifying the HTML, I'm thinking about adding a CSS class to the elements that should be removed from the export.

The only way that seems to come close is exportOptions from the Buttons API, but I cannot figure out how to modify the data before export. Could you please give a hint?

This question has an accepted answers - jump to answer

Answers

  • c7hc7h Posts: 3Questions: 1Answers: 1

    I discovered now the customize: (window, button, dt) => {...} option but I cannot select the elements that I want to remove from the DOM of the print window with window.document.body.querySelectorAll('.noexport'); because the HTML has already been cleaned.

  • c7hc7h Posts: 3Questions: 1Answers: 1
    Answer ✓

    I managed to do it with exportOptions, see: https://live.datatables.net/sumolevi/2/edit

    The comments brought me on the right track.

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Hi,

    Thanks for the update. Good to hear you found a solution!

    Allan

Sign In or Register to comment.