Hide filter on button output

Hide filter on button output

georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

I have a table where I have included a filter on a column.

I have column totals in the footer as well, which I want to show on the output (PDF, CSV, print etc)

I have enabled the footer to be added to the output, but I also get the undesired filter code as well. When I set striphtml to true, I get left with the items that were in the filter drop down.

Is it possible to tell the table to output an empty cell rather than the filter code?

Example is here - http://flywestwind.org/testcases/PassengerPilots.php

Thanks

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,939Questions: 87Answers: 415
    edited April 2020 Answer ✓

    You could try orthogonal data using type === 'export'
    https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html

    If that is not possible for the footer you can try export options
    https://datatables.net/extensions/buttons/examples/html5/outputFormat-function

    https://datatables.net/reference/button/excelHtml5 and more details about export options here
    https://datatables.net/reference/api/buttons.exportData()

    You can also access the footer:

    This should show you how to do this ... more or less:

    //custom button for cashflow csv generation
    $.fn.dataTable.ext.buttons.csvCashFlow = {
        extend: 'csv', fieldSeparator: csvSep, charset: 'UTF-8', bom: true,
                       filename: cashFlowTitle,
        exportOptions: {
            columns: function(column, data, node) {
                if (column > 17) {
                    return false;
                }
                return true;
            },
            modifier: { selected: null }, //make sure all records show up!!
            format: {
                body: function ( data, row, column, node ) {
                    if (typeof data !== 'undefined') {
                        if (data != null) {  
                            var i=0;  //get rid of the currency ISO codes
                            while ( cur[i] ) {
                                if ( data.search( cur[i] ) > -1 )   {
                                    data = data.split(cur[i]).join("");
                                }
                                i++;
                            }
                            //rate must be adjusted to fraction to be able to calculate
                            if (column == 4 || column == 16) {
                                if (data !== '') {
                                    if (lang === 'de') {
                                        //replace the only comma with a period
                                        data = data.toString().replace(",", ".");
                                    }
                                    data = data / 100;
                                    if (lang === 'de') {
                                        //replace the only period with a comma                                        
                                        data = data.toString().replace(".", ",");
                                    }
                                }
                            }
                        }
                    }
                    return data;
                },
                header: function ( data, column ) {
                    return data;
                },
                footer: function ( data, column ) {
                    //do something to modify the data
                    return data;
                }
            }
        }
    };
    

    And here is a thread dealing with the footer in export options as well:
    https://datatables.net/forums/discussion/comment/106393/#Comment_106393

  • georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

    I have updated the exportoptions section to be this

    exportOptions: 
    {
        stripHtml: true,
        columns: [0, 1, 2, 3, 4, 5, 6],
        format: 
        {   body: function (data, row, column, node)
            {
                return data;
            },
            header: function( data, row, column, node)
            {
                return data;
            },
            footer: function ( data, row, column, node ) 
            {
                if (column == 3)
                {
                    data = "3";
                }
                else if (column == 1)
                {
                    data = "1";
                }
                else
                {
                    data = "*";
                }                                           
                return data;
            }
        }
    }
    

    However I only see the * character in the footer. I also tried with just the data and column as parameters, but that didn't work either. I'm thinking that column is not an integer, although your example implies that it is for the body section. Is the footer section different

    The test case has been updated

  • georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

    OK, found out the issue,

    The footer parameters are only data and column, rather than data, row, column, node that one of the linked examples suggested

This discussion has been closed.