Export everything if no items are selected?

Export everything if no items are selected?

garymhgarymh Posts: 3Questions: 1Answers: 0

Hi - I have a table using HTML data and the jquery-datatables-checkboxes plugin to display some information I'd like to export. I know I could do something like an "Export all" and then an "Export selected" button, but ideally I'd like just one button that would export all the displayed rows if nothing is selected (and, of course, just the selected rows if there is a selection).

Hopefully that makes sense! I'd be glad to provide a debugger session if needed. Here's the code:

              var table = $('#member_table').DataTable({
                // l - length changing input control
                // f - filtering input
                // t - The table!
                // i - Table information summary
                // p - pagination control
                // r - processing display element
                'dom': 'fBrtip',
                'paging': false,
                'autoWidth': false,
                searchPane: {
                  columns: '.filterable',
                  threshold: 0
                },
                'stateSave': true,
                'stateDuration': 0,
                'buttons': [

                    {
                      text: '<i class="fa fa-plus"></i> Add to list',
                      className: 'btn btn-primary',
                      titleAttr: 'Add to list',
                      action: function ( e, dt, button, config ) {
                        window.location = '<%= [rails url] %>';
                      }
                    },
                  {
                    extend: 'selected',
                    text: '<i class="fa fa-edit"></i> Edit Multiple',
                    className: 'btn btn-info',
                    titleAttr: 'Edit Multiple',
                    action: function ( e, dt, button, config ) {
                      $('#edit_multiple_form').submit();
                    }
                  },
                  {
                    extend: 'colvis',
                    text: '<i class="fa fa-filter"></i> Show Columns',
                    className: 'btn btn-warning',
                    titleAttr: 'Select Columns'
                  },
                  {
                    extend: 'print',
                    text: '<i class="fa fa-print"></i>',
                    titleAttr: 'Print',
                    exportOptions: {
                      columns: ':visible :not(.sorting_disabled)'
                    }
                  },
                  {
                    extend: 'collection',
                    text: '<i class="fa fa-share"></i> Export',
                    buttons: [
                      {
                        extend: 'excelHtml5',
                        exportOptions: {
                          rows: { selected: true },
                          columns: ':visible :not(.sorting_disabled)'
                        }
                      },
                      {
                        extend: 'csvHtml5',
                        exportOptions: {
                          rows: { selected: true },
                          columns: ':visible :not(.sorting_disabled)'
                        }
                      }
                    ]
                  }
                ],

                'columnDefs': [
                  {
                    'targets': 0,
                    'checkboxes': {
                      'selectRow': true
                    }
                  }
                ],
                'select': {
                  'style': 'multi'
                },
                'order': [[1, 'asc']]
              });

Answers

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    That is something I'd like to add to Buttons, but it isn't currently a feature that is available I'm afraid.

    Allan

  • garymhgarymh Posts: 3Questions: 1Answers: 0

    Thanks Allan! Put me down for a feature request then :)

This discussion has been closed.