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

Export to Excel not working on table filter

$
0
0

My data table is working with its filter and search functionality:

function filterTable(targetTable) {
    let mappedStatus = $('input:radio[id=optFilter]:checked').val();

    if (mappedStatus !== 'undefined') {
        if (mappedStatus !== 'A') {
            targetTable.columns(3).search(mappedStatus).draw();
        } else {
            targetTable.columns(3).search("").draw();
        }
    }
}

And here is datatable definition:

function reloadTable2(data) {
    if ($.fn.DataTable.isDataTable("#tblPayFiles")) {
        $('#tblPayFiles').DataTable().destroy();
    }

    if (data !== null) {
        var table = $('#tblPayFiles').DataTable({
            lengthChange: false,
            buttons: [
                {
                    titleAttr: 'Export to Excel',
                    extend: 'excelHtml5',
                    className: 'btn btn-success d-none',
                    text: 'Export To Excel',
                    title: '',
                    filename: getExcelFileName(),
                    exportOptions: {
                        columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                        messageTop: null
                    }
                }
            ],
            pageLength: 10,
            destroy: true,
            data: data.details,
            deferRender: true
        });

        return table;
    }
}

The export to excel works properly when the table is freshly loaded. however when filters are applied, note that it will redraw (not reload) the table, and the results are correct. the export to excel suddenly doesn't work anymore. even if i remove the filters, the export doesn't work anymore and I am suspecting that the draw() function seem to remove the event listener for the export. any help on maintaining the export to excel even after filter? the example in this link: https://datatables.net/extensions/buttons/examples/initialisation/export.html, the export to excel works on filter because it uses the default filter.


Viewing all articles
Browse latest Browse all 82800

Trending Articles



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