Best way to purge/hard reset the table data?

Best way to purge/hard reset the table data?

growe19growe19 Posts: 18Questions: 6Answers: 0
edited April 2022 in General

I've noticed on the odd occassion my table displaying two sets of data from my ajax/json/localhost source. I'm pointing the fingure at the API app I'm using but to be sure I'd like to have a button for a hard reset of the table data.

Is it possible to have a button to reset the source?

        {
        text: 'Reset Table', 
        action: function ( e, dt, node, config ) { 

table.destroy();
    //how do i reload the same source I killed

        }
        },

Link to test case: https://garyrowe.co.uk/acc/?mode=live&hide=0&order=1&class=
If you would like data to appear you will need the sim racing game Assetto Corsa Competizione, SimHub and the Swoop plug-in for SimHub.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited April 2022 Answer ✓

    You can just wrap the data table into a function. You call the function and the data table gets initialized. Just destroy it before you call the function again. Or do something like this:

    var initDataTable = function() {
        if ( $.fn.DataTable.isDataTable( '#yourTable' ) ) {
             table.destroy();
        }
        ... init your data table ...
    }
    

    Alternatively you can add this option to your dt configuration. Then you can call the function as many times as you like. Your table always gets destroyed and rebuilt.

    destroy: true
    

    https://datatables.net/reference/option/destroy

Sign In or Register to comment.