DataTable Export to excel adds a new row before exporting

I'm going straight to the point. I am trying to export an excel file using datatbable ... however I want to add a new line before exporting the file. I am really new to datatable, so please bear with me.

this is what i have done so far.

in part customize:function()I want to add new lines before the heading ... the heading is actually a parameter for generating the table.

Example:

NAME:SampleName

Date From: 2016-05-01

Date To: 2016-05-31

  /*dataTables*/
    var handleDataTableButtons = function() {
      if ($("#datatable-responsive-returns-report").length) {
        $("#datatable-responsive-returns-report").DataTable({
         "bSort": false,
          scrollX: true,
          iDisplayLength: 50,
          dom: "Bfrtip",
           buttons: [
              // 'copy', 'csv', 'excel', 'pdf', 'print'
              {
                extend:"copy",
                className:"btn-sm"
              },
              {
                extend:"excel",
                className:"btn-sm",
                text:"Export to Excel",
                customize:function(xlsx){
                  var sheet = xlsx.xl.worksheets['sheet1.xml'];
                  console.log(sheet);
                  /add new row
                },
                filename: ($(".universal_name option:selected").text() == "" ? $(".hid_universal_name").val() : $(".universal_name option:selected").text()) + " - " + $(".universal_title").val()+"("+$(".date_from").val()+" to "+$(".date_to").val()+")"
              }
          ],

        });
      }
    };

    TableManageButtons = function() {
      "use strict";
      return {
        init: function() {
          handleDataTableButtons();
        }
      };
    }();

thanks in advance...

+4
source share

Source: https://habr.com/ru/post/1653239/


All Articles