How to clear all Filter/Sorts/Pagination (without reinitializing the table from scratch)

How to clear all Filter/Sorts/Pagination (without reinitializing the table from scratch)

Eugene_BEugene_B Posts: 19Questions: 8Answers: 0
edited December 2018 in Free community support

is there an easy way to reset a DataTable to its original state by removing all Filters/Sorts/Pagination the user may have applied? I want to return to the "blank state."

I posted previously that I found a way to do it by doing clear/destroy and then reinitialization,

var activeRequestsTable = $('#activeRequestsTable').DataTable();
activeRequestsTable.state.clear();
activeRequestsTable.destroy();
    $('#activeRequestsTable').DataTable({
           "ajax": {
            url: myUrl, 
            dataSrc: 'activeRequests',
            type: 'POST',
            //etc.
        }
    },
    "columns": [ .. ]
    });

But that is a performance hit because I'm refetching data for the table. I have all the table data, I just need to reset the state quickly back to blank.

Replies

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

    Hi @Eugene_B ,

    No, there's no, I'm afraid to say - the only guaranteed way is to destroy() and reinitialise, but that would refetch data as you said. You can clear searches and pagination easily with search() and page() respectively, but the ordering is a pickle as clearing it with order() can leave residue of previous searches...

    Cheers,

    Colin

This discussion has been closed.