Reinitialize datatable

Reinitialize datatable

chaitchait Posts: 5Questions: 2Answers: 0

Hi,

I am using 'data' to initialize table. Now I want to reload the data to the table making external ajax call and pass the data. how to reinitialize the datatable I see ajax.reload is the option to reload the datatable. Since I am making ajax call in the script and passing the data to the datatable. What are my options to reload the datatable now?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,871Questions: 1Answers: 10,522 Site admin
    Answer ✓

    If you are making the Ajax call yourself, use clear() and rows.add() to first clear the table and then add the new data. Finish with a call to draw().

    Allan

  • chaitchait Posts: 5Questions: 2Answers: 0
    edited March 2017

    Hi Allan,

    Thanks for the reply I did the same thing, as you suggested.

    Below is code sample,

    function testDataTables() {

    $("#testTab").DataTable({
        paging : false,
        searching : false,
        info : false,
        order : [[0, "desc"], [5, "asc"]],
        data : testJSON.demo1,
        columns : [{
                data : "record.recordData.openedTime",
                defaultContent : "test",
                render : renderRecordOpend
            }]
      });
      }
    
    function testUpdatedDatatable(){
    $('#testTab').DataTable().clear().rows.add(response.demo1).draw();
    }
    

    Thing is this piece of code is working as expected in Chrome,
    but somehow it's not working in Internet explorer.

    I am having hard time figuring this issue could you help me out.

    Thanks,
    chait.

  • chaitchait Posts: 5Questions: 2Answers: 0

    Hi Allan,

    I figured out this issue. In datatables api which makes ajax calls has set the cache to false. In my external ajax call which I use to initialize the datatable caches the response, so any subsequent calls to the server still uses the previous response.

    Thanks,

  • allanallan Posts: 63,871Questions: 1Answers: 10,522 Site admin
    Answer ✓

    Thanks for posting back. Good to hear you have it working now.

    Allan

This discussion has been closed.