Export All to Excel, PDF, etc when using Server Side Processing

Export All to Excel, PDF, etc when using Server Side Processing

ckreedyckreedy Posts: 1Questions: 1Answers: 0

I am currently using server side processing for my datatables and I understand that the buttons api will only export the visible rows when the button is pressed as the others are not yet rendered in the dom. Therefore, I want to extend the button such that when someone clicks on one of the export buttons, it will first show all rows in the table and then run the usual export process. I have been experimenting with the following datatables setting but it is not working. Is there something else that I need to do?

Everything else is working perfectly.

var metrics_data_table = datatable_object.DataTable({
  'processing': true,
  'serverSide': true,
  'lengthChange' : false,
  'ajax': {
      'url': datatable_settings.url,
      'type':  'POST',
      'data': {
          'form_filter': $(".javascript__datatables_display__form :input").serialize(),
          'csrfmiddlewaretoken': $('.javascript__data_tables_display__csrf_token').val()
      },
  },
  'columns': datatable_settings.columns,
  'order':  datatable_settings.order,
  'columnDefs': datatable_settings.columnDefs,
  'createdRow': datatable_settings.createdRow,
  'initComplete': function(){
    datatable_object.fadeIn();
    var api = this.api();

    new $.fn.dataTable.Buttons(api, {
      'buttons': [
        'colvis',
      ]
    });
    new $.fn.dataTable.Buttons(api, {
      'buttons': [
        'copy',
        'csv',
        'excel',
        {
          'extend': 'pdfHtml5',
          'orientation':  'landscape',
          'pageSize':  'LETTER',
          'exportOptions':
          {
            'columns':  ':visible'
          },
          'action': function(e, dt, button, config) {
            // Add code to make changes to table here
            metrics_data_table.settings().page.len(-1);
            metrics_data_table.settings().drawCallback = function (settings) {
            // Call the original action function afterwards to
            // continue the action.
            // Otherwise you're just overriding it completely.
                $.fn.dataTable.ext.buttons.pdfHtml5.action(e, dt, button, config);
            }
            metrics_data_table.draw();
          }
        }
      ]
    });

Answers

This discussion has been closed.