title: DataTables Custom Button Export update Header
body: <p>I am using Export plugin on DataTables to export filtered results from a table. You can either export an excel file by choosing a select dropdown above the column header or click the custom button that filters the results for you, like a pre-built filter. (I am utilizing selectpicker too). However, when you use the filter feature in DataTables you have to rewrite the column headers. otherwise, you get header titles with all the data from the select. So I added a rewrite for the header for the 'excelHtml5' button. This works great! But it won't work on my custom button, 'Export Offline'. Does anyone know of the solution?</p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function () {
  function getSearchParams(k){
      var p={};
      location.search.replace(/[?&amp;]+([^=&amp;]+)=([^&amp;]*)/gi,function(s,k,v){p[k]=v})
      return k?p[k]:p;
  }
  
  
  var devicelist = $('#newdevicelist').DataTable({
          keys: true,
          autoFill: true,
  
          'iDisplayLength': 20,
          dom: 'Bfrtip',
          buttons: [
              {
                  extend: 'excelHtml5',
  
  
                  title: $("#report_title").val(),
                  exportOptions: {
                      format: {
                          header: function (data, columnIdx) {
                              return writeTitle(columnIdx) != '' ? writeTitle(columnIdx) : data;
  
                          },
  
                      }
                  }
              },
  
              {
                  text: 'Export Offline',
                  title: 'Offline Report',
                  filename: 'Offline Report',
   exportOptions: {
                      columns: ':visible',
                      format: {
                          header: function (data, column) {
                              return writeTitle(column) != '' ? writeTitle(column) : data;
  
                          },
  
                      }
                  },
                  action: function ( e, dt, node, config ) {
                      devicelist.search('').draw();
                      filterColumn( 5, 'Down');
                      filterColumn( 6, 'Disconnected');
                      filterColumn( 7, 'Offline');
  
                      $.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
                  },
  
              }
  
  
  
  
  
          ],
          "initComplete": function (settings, json) {
  
              this.api().columns([2, 4, 5, 6, 7, 8, 9, 10, 12, 13]).every(function () {
                  var column = this;
                  var header = this.header();
  
                  var select = $('&lt;select multiple class="selectsearch selectpicker' + column.index() + '" rel="' + column.index() + '" title="' + $(header).html() + '"&gt;&lt;optgroup label="' + $(header).html() + '"&gt;&lt;option&gt;&lt;/option&gt;&lt;/optgroup&gt;&lt;/select&gt;')
                      .appendTo($(column.header()).empty())
  
                  column.data().unique().sort().each(function (d, j) {
  
                      d = d.split('&lt;p style="font-size: .01em;"&gt;').pop().split('&lt;/p&gt;').shift();
  
                      if ( d != "" ) {
                          select.append('&lt;option value="' + d + '"&gt;' + d + '&lt;/option&gt;')
                      }
                  });
              });
  
              $('.selectpicker2, .selectpicker3, .selectpicker4, .selectpicker5, .selectpicker6, .selectpicker7, .selectpicker8, .selectpicker9, .selectpicker10, .selectpicker12, .selectpicker13').selectpicker({
                  style: 'btn-default',
                  size: 4
              });
  
  
              $('#clear-all-cache').show();
              $('.select-type').show();
  
              $('.buttons-excel').html("&lt;i class='fa fa-fw fa-file-excel-o'&gt;&lt;/i&gt; Excel");
  
              $('div.dt-buttons').prepend('&lt;a class="dt-button bg-blue buttons-html5" id="reset-list" href="#"&gt;Reset List&lt;/a&gt;'               );
  
  
  
          },
  
  
      });
      function filterColumn(i, search) {
    //   alert( search + ' - ' + i);
  
      //  var query = "((  )|^)" + regex_escape(search) + "((  )|$)";
      $('#newdevicelist').DataTable().column(i).search(
          search,
          1, 0
      ).draw();
  
  
  }
      });
  </code></pre>