How to set default properties for exporting Buttons?

How to set default properties for exporting Buttons?

nicksggnicksgg Posts: 1Questions: 1Answers: 0
edited January 2020 in Free community support

Hi, I've custom settings for all DataTables in my project but now i need to add title, messageTop and messageBottom for every DataTables during exporting to excel.

I have tried the method provided from this question but it does not work. JsFiddle The title, messageTop and messageBottom seem to be overwritten when it is re-declare in the dataTables.

$.extend(true, $.fn.dataTable.defaults, {
  searching: false,
  buttons: {
    buttons: [{
      title: 'global title',
      messageTop: 'global same message top',
      messageBottom: 'global same message bottom'
    }]
  }
});
$(document).ready(function() {
  $('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [{
      extend: 'excelHtml5',
      text: 'TableOneExport'
    }]
  });

  $('#paylist').DataTable({
    dom: 'Bfrtip',
    buttons: {
      buttons: [{
        extend: 'excelHtml5',
        text: 'TableTwoExport'
      }]
    }
  });
});

Please help. Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    You could do:

    $.fn.dataTable.ext.buttons.excelHtml5.messageTop = '...';
    

    It's not idea, but currently there is no way to set defaults that will extend the buttons, in part because each button type can define its own options, so you need to set them per button.

    Allan

This discussion has been closed.