CSV Button: Refresh table prior to downloading CSV

CSV Button: Refresh table prior to downloading CSV

nathan4unathan4u Posts: 2Questions: 1Answers: 0
edited July 2018 in Free community support

I'm putting together some custom tables that utilize Datatables and its included CSV button. However, there are a number of table cells that act as forms, such as these .
If a user edits any of these forms and then clicks Download CSV without refreshing the page, those form changes won't persist in the download. Does anyone know the simplest way to have the button trigger a refresh of the datatable prior to generating the CSV file? It's a bit trickier than a traditional JS button as this is embedded in datatables. Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946
    Answer ✓

    I'm guessing you are using Datatables APIs to update the table from the form submit. If so then you will need to use one of the invalidate() API's like rows().invalidate() for Datatables to update its data cache. But I'm just guessing since you didn't post your code.

    Kevin

  • nathan4unathan4u Posts: 2Questions: 1Answers: 0

    Thanks for the suggestion! The issue ended up requiring a full server-side reload of the table. I ended up with the following:

    action: function (e, dt, node, config) {
      $table.dataTable().api().ajax.reload(() => {
        $.fn.dataTable.ext.buttons.csvHtml5.action.call(this, e, dt, node, config);
       });
    

    This way, you synchronously reload prior to generating the CSV file.

This discussion has been closed.