How to remove dropdown filter select values from header when export to excel pdf

How to remove dropdown filter select values from header when export to excel pdf

akgbastiakgbasti Posts: 1Questions: 1Answers: 0
 $(document).ready(function() {
            $('#invoicetable').DataTable( {
                dom: 'lBfrtip',
                buttons: [
            { extend: 'print', filename: 'Pay Summary',title: 'Pay Summary',footer: true },
            { extend: 'excelHtml5', filename: 'Pay Summary',title: 'Pay Summary',footer: true },
            { extend: 'pdfHtml5', filename: 'Pay Summary', title: 'Pay Summary', footer: true },
        ],
                initComplete: function () {
                    this.api().columns([0,2]).every( function () {
                        var column = this;
                        var select = $('<select><option value=""></option></select>')
                            .appendTo( $(column.header()).empty() )
                            .on( 'change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()
                                );

                                column
                                    .search( val ? '^'+val+'$' : '', true, false )
                                    .draw();
                            } );

                        column.data().unique().sort().each( function ( d, j ) {
                            select.append( '<option value="'+d+'">'+d+'</option>' )
                        } );
                    } );
                },
                
                "footerCallback": function ( row, data, start, end, display ) {
            var totapi = this.api(), data;
 
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
            pageTotal = totapi
                .column( 3, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

                saltot = totapi
                .column( 5, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

                dectot = totapi
                .column( 6, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

                salpay = totapi
                .column( 7, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
               
            // Update footer
            $( totapi.column( 3 ).footer() ).html(pageTotal);
            $( totapi.column( 5 ).footer() ).html(saltot);
            $( totapi.column( 6 ).footer() ).html(dectot);
            $( totapi.column( 7 ).footer() ).html(salpay);
        }
                   
            } );
            
        } );

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @akgbasti ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • nilakshibhosalenilakshibhosale Posts: 7Questions: 2Answers: 0

    Hi @colin

    I am also having same issue, can anybody help on this issue?

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    For reference, @nilakshibhosale resolved this and posted his solution onto this thread.

This discussion has been closed.