Save table to excel with header - in header are inputs

Save table to excel with header - in header are inputs

dandoodandoo Posts: 3Questions: 1Answers: 0

Hello,

I have a table where in header I have inputs to filtering and I would like also to use Save button to excel. Problem is that excel file have empty header in that case.

How to add header to excel maybe placeholder or name of input?

$('#itemsJS thead th').each( function () {
    var title = $(this).text();
    if (title != ''){
      $(this).html( '<input type="text" name="'+title+'" class="form-control" placeholder="'+title+'" />' );
    }
} );

$('#itemsJS').DataTable({
  ordering:  false,
  scrollX: true,
  dom: 'Bfrtip',
  buttons: [
    {
        extend: 'excelHtml5',
        text: 'Zapisz do Excel',
        className: 'btn btn-success',
    },
    {
      extend: 'pdfHtml5',
      text: 'Zapisz do PDF',
      className: 'btn btn-success',
      orientation: 'landscape',
      pageSize: 'LEGAL'
    }
  ],
  initComplete: function () {
      // Apply the search
      this.api().columns().every( function () {
          var that = this;

          $( 'input', this.header() ).on( 'keyup change clear', function () {
              if ( that.search() !== this.value ) {
                  that
                      .search( this.value )
                      .draw();
              }
          } );
      } );
  }
});

Answers

This discussion has been closed.