Extract excel error: undefined (reading 'length') from footer

Extract excel error: undefined (reading 'length') from footer

imneckroimneckro Posts: 4Questions: 1Answers: 0

WHen I'm trying to extra excel, footer throws error:

buttons.html5.min.js:8 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at buttons.html5.min.js:8:21584
at _Api.action (buttons.html5.min.js:8:21857)
at run (dataTables.buttons.js:807:19)
at dataTables.buttons.js:822:7

If remove footer excel exports fine.
Here is my code:

                  $('#getvatinfo').dataTable({
                      dataSrc: '',
                      bPaginate: false,
                      "info": false,
                      "paging": false,
                      layout: {
                          topStart: {
                              buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
                          }
                      },
                      columnDefs: [{
                              target: 1,
                              render: function(data) {
                                  return moment(data).format('DD/MM/YYYY');
                              }
                          },
                          {
                              targets: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42],
                              render: DataTable.render.number(null, null, 2, '')
                          }
                      ],
                      "language": {
                          "search": "Αναζήτηση"
                      },
                      "footerCallback": function(row, data, start, end, display) {
                          var api = this.api(),
                              data;

                          // Remove the formatting to get integer data for summation
                          var intVal = function(i) {
                              return typeof i === 'string' ?
                                  i.replace(/[\$a-zA-Z, ]/g, '') * 1 :
                                  typeof i === 'number' ?
                                  i : 0;
                          };

                          var cols = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42]; // your columns position will come in this array

                          for (let index = 0; index < cols.length; index++) {
                              var col_data = cols[index];
                              // Total over all pages
                              total = api
                                  .column(col_data)
                                  .data()
                                  .reduce(function(a, b) {
                                      return intVal(a) + intVal(b);
                                  }, 0);

                              // Total over this page
                              pageTotal = api
                                  .column(col_data, {
                                      page: 'current'
                                  })
                                  .data()
                                  .reduce(function(a, b) {
                                      return intVal(a) + intVal(b);
                                  }, 0);

                              // Update footer
                              $(api.column(col_data).footer()).html(
                                  pageTotal.toLocaleString('el-GR', {
                                      minimumFractionDigits: 2
                                  })
                              );
                          }

                      },
                      initComplete: function(settings, json) {
                          $("#perfrom").text(datefrom);
                          $("#perto").text(dateto);
                          fillper();
                      }
                  });

Answers

Sign In or Register to comment.