Is there a way for Export to Excel to include info and infoFiltered?

Is there a way for Export to Excel to include info and infoFiltered?

badijdbadijd Posts: 9Questions: 4Answers: 0

Looking for a way when a user uses the Export to Excel option, that the Info (ex: Showing 1 to 17 of 17 records) and the infoFiltered (ex: Showing 1 to 2 of 2 records (filtered from 17 total records)) is included.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    Use page.info() to get that info. Use messageTop or messageBottom as a function to get the page.info() then place it in the export where desired. See this example.

    Kevin

  • badijdbadijd Posts: 9Questions: 4Answers: 0
    edited November 2023

    Thank you kthorngren! I was able to get this to work; however, I feel there has to be something to make it a bit easier.
    In the export button I call a function:

    messageTop: exportinfo
    
    function exportinfo() {
      var table = $('#example').DataTable();
      var info = table.page.info();
        
      return table.page.info().recordsTotal;
    };
    

    This can be expanded to display the following:
    Exported 17 records

    If I am using searchPanes or Search and export the results I want to display:
    Exported 2 records (filtered from 17 total records)

    How do I capture when the view has been filtered?

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited November 2023 Answer ✓

    Use recordsDisplay to determine if there are filtered records. Something like this:
    https://live.datatables.net/veluwize/1/edit

            var info = table.page.info();
            
            if (info.recordsDisplay === info.recordsTotal) {
              records = info.recordsTotal + ' entries';
            } else {
              records = info.recordsDisplay + ' entries (filtered from ' + info.recordsTotal + ' total entries)';
            }
    
            return records;
    

    Kevin

  • badijdbadijd Posts: 9Questions: 4Answers: 0

    Thank you for the quick response. Works perfect!

Sign In or Register to comment.