Copy/export all selected rows when the search filter is activated

Copy/export all selected rows when the search filter is activated

SjeeshSjeesh Posts: 4Questions: 1Answers: 0

https://datatables.net/extensions/buttons/examples/initialisation/select.html

It's likely someone would export his selection after a final search input but when the search filter is active only the selected rows that are active on the screen are exported.

Is this possible to export everything, including the selected rows that are hidden while the filter is active? My attempts at clearing/resetting the filter onclick and exporting every selected row have been fruitless...

$("#example").DataTable().search("").draw()

This question has an accepted answers - jump to answer

Answers

  • SjeeshSjeesh Posts: 4Questions: 1Answers: 0
    $('#example').DataTable( {
        buttons: [
            {
                extend: 'excelHtml5',
                text: 'Excel',
                customizeData: function( e, dt, node, config ) {
                                $("#example").DataTable().search('').draw()
                            },
                exportOptions: {
                    modifier: {
                        selected: true
                    }
                }
            }
        ]
    } );
    

    This is clearing the active search filter but still only the selected rows that were visible onscreen when the filter was active are copied to excel. You have to click the button twice.

    It has something do to with sequencing... Anyone know if this is posibble ?

    The example in the manual has the same problem so maybe it's a limitation?

    https://datatables.net/extensions/buttons/examples/initialisation/select.html

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

    To be clear, are you saying you want to export just the selected rows, regardless of what the search filter is?

    Colin

  • SjeeshSjeesh Posts: 4Questions: 1Answers: 0

    Yes. When the export button is pressed i would like every row that has been selected in the table to be exported. When the search filter is active the selection is incomplete because of the filter.

    When you're dealing with a very large table, you have to make use of the search filter to find the requested data. I've noticed people who want to copy or export their selection don't get all the selected rows with the standard buttons because the search filter is still active with their last search query.

    My attempts to clear the filter and copy the selected data are not working.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    edited January 2020 Answer ✓

    You can use selector-modifier to determine what gets exported. Here, it's exporting only selected rows, and ignoring the search: http://live.datatables.net/weqeboje/1/edit

    Colin

  • SjeeshSjeesh Posts: 4Questions: 1Answers: 0

    Thank you!

This discussion has been closed.