Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82267

csvHtml5.action.call() results in JavaScript error: Uncaught TypeError: n is not a function

$
0
0

I am using server-side processing and would like to dynamically set the following config prior to exporting:

                  exportOptions: {
                      modifier: { search: 'applied', page: 'all' } // Ensure all even paginated rows are included in export.
                  }

After dynamically setting the config, I need to then dynamically export all rows upon clicking the CSV button.

I could not figure out how to do this so, as an acceptable alternative, I am dynamically changing the "Display Results" dropdown list via the following action export:

      {
        extend : 'csvHtml5',
        action: function(e, dt, button, config) {
          console.log("CSV export action triggered.");
          // Check if server-side processing is enabled
          if (dt.settings()[0].oFeatures.bServerSide) {
              var originalPageLength = dt.page.len(); // Store original page length

              // Change page length to `-1` to load all data
              dt.page.len(-1).draw().one('draw', function() {
                  console.log("All rows loaded, triggering export.");

                  // Trigger the default CSV export action
                  $.fn.dataTable.ext.buttons.csvHtml5.action.call(this, e, dt, button, config);

                  // Restore previous page length after export
                  setTimeout(() => {
                      dt.page.len(originalPageLength).draw();
                      console.log("Page length restored to", originalPageLength);
                  }, 1000);
              });
          } else {
              // If not server-side, trigger export normally
              $.fn.dataTable.ext.buttons.csvHtml5.action.call(dt.button(button[0]), e, dt, button, config);
          }
        },
      },

The problem with this approach, is that the following csvHtml5.action.call() reports the following JavaScript error:

Uncaught TypeError: n is not a function

Believe or not, the export still appears to work! However, because of the JavaScript error, the following call fails and does not reset to the previous page length after export.

$.fn.dataTable.ext.buttons.csvHtml5.action.call(this, e, dt, button, config);

I have spent too much time going round and round with an AI bot. I need a real person with real intelligence to take a look. :)

I am using the following CDN:

    <!-- Preload and defer DataTables CDN and local configuration -->
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js" as="script">
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js" as="script">
    <link rel="preload" href="https://cdn.datatables.net/v/zf/dt-2.2.2/b-3.2.2/b-colvis-3.2.2/b-html5-3.2.2/b-print-3.2.2/fh-4.0.1/sr-1.4.1/datatables.min.js" as="script">
    
    <!-- DataTables CDN -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js" defer></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js" defer></script>
    <script src="https://cdn.datatables.net/v/zf/dt-2.2.2/b-3.2.2/b-colvis-3.2.2/b-html5-3.2.2/b-print-3.2.2/fh-4.0.1/sr-1.4.1/datatables.min.js" defer></script>

Viewing all articles
Browse latest Browse all 82267

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>