Example localStorage get the JSON array

Example localStorage get the JSON array

webworkerwebworker Posts: 3Questions: 1Answers: 0

Hello everybody,

the example https://editor.datatables.net/examples/advanced/localstorage.html suits my project.
How can I retrieve the complete JSON array and then delete the local store?

<button onclick="getResults()">get results as JSON array</button>
   //that doesn't work
    function getResults(){

        //Get all records as JSON array.
        var str = JSON.stringify(editor.formData());
        document.getElementById("myResults").innerHTML = str;

       //Delete localDatastorage
        $('#example').DataTable().state.clear();
        window.location.reload();
    }

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @webworker ,

    If you look at that page you linked to, there's an example around line 52 where that data is being removed. However, if it is deleted, that data won't be available for when the page is next loaded.

    Cheers,

    Colin

  • webworkerwebworker Posts: 3Questions: 1Answers: 0

    Hi Colin,

    this is a method within the AJAX call. I would like to delete by clicking on the button. The question is, what's the syntax to access the editors DataSet?

    In line 1 the editor var is set globally. It would have to be done but how?

    regards

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Use rows().data() (and add toArray() to get a plain array rather than a DataTables API instance) to get the data from the table. This effectively uses DataTables as the data store (not Editor).

    Allan

  • webworkerwebworker Posts: 3Questions: 1Answers: 0

    Perfect, that's what I mean Allan.

    $('#example').DataTable().rows().data().toArray()
    
This discussion has been closed.