How can I set a footer property in JSON export of DataTable?

How can I set a footer property in JSON export of DataTable?

gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0
edited December 2021 in DataTables

There is a footer property in datatable which export the footer data

{
                    extend: 'csv',
                    footer: true,
                    exportOptions: {
                        columns: ':visible'
                    }
                },
footer : true, property allows to export footer data to csv file.

How can I set this same property in below code

{
                text: 'JSON',
                action: function ( e, dt, button, config ) {
                    var data = dt.buttons.exportData();
 
                    $.fn.dataTable.fileSave(
                        new Blob( [ JSON.stringify( data ) ] ),
                        'Export.json'
                    );
                }
            }

Is this possible ? Please help me any solution. Thanks in advance.

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    Answer ✓

    The easiest way would be to use an existing button, and just modify the action function, something like this:

            buttons: [{
              extend: 'csvHtml5',
              footer: true,
              action: function(e, dt, button, config) {
                var data = dt.buttons.exportData();
    
                $.fn.dataTable.fileSave(
                  new Blob([JSON.stringify(data)]),
                  'Export.json'
                );
              }
            }]
    

    Coln

  • gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0

    Thanks @colin for the reply let me check this in our scenario. Thank you.

Sign In or Register to comment.