Can I force a combination of some non-visible columns + visible columns into the export file ?

Can I force a combination of some non-visible columns + visible columns into the export file ?

mmarzsmmarzs Posts: 12Questions: 4Answers: 0

Hi!
I am trying to make a collection of export options on my table and was wondering if there was a way for my "Export Visible Columns Only " for me to include a few of my non-visible columns that have a class on them of ".always-export"? There are some standard fields that they don't see in the table that I want to make sure are included in combination with the visible columns.

  {
  extend: 'collection',
  "text": '<i class="far fa-file-excel mr-3 ml-3"></i>',
  className: 'btn-data-table btn-sm m-b-xs d-print-none data-table-icon-btn d-none d-sm-block',
  buttons: [

        {
          extend: 'excelHtml5',
          "text": '<i class="far fa-file-excel mr-2"></i>Export Visible Columns Only (* not included)',
          "title":'',
          titleAttr: 'Use the Column Selectors to select the columns to include in your export. Constituent First Name and Last will always be included. Columns with a * contain combined data and are not exportable. All other columns must be selected using the Column Selector before export..',
          "filename": '{{export_file_name}}', 
          "exportOptions": {
            columns: ':visible', // want to also include the class of .always-export (which is different then the visible columns)
            "modified": {
              filter:true
            }
          }
        }   
  ],
  attr:  {
    id: 'ExportButtonCollection'
  }
  }

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Yep, the exportOptions.columns is column-selector, which can be a function - so in there you can return both visible and with the class.

    Colin

  • mmarzsmmarzs Posts: 12Questions: 4Answers: 0

    @colin would it be something like this?

    "exportOptions": { columns: function () { var columns = table.columns( [0,1,2,':visible:not(.never)'] ); return columns },

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    No, the function needs to return true or false - it gets called for each of the columns. This is the example from the reference page I linked to in my last reply,

    var table = $('#example').DataTable();
     
    var active = table
        .columns( function ( idx, data, node ) {
            return $.inArray( 'Active', data ) !== -1 ?
                true : false;
        } )
        .data();
    

    Colin

Sign In or Register to comment.