How do I clear and reload the the data in dataTable()?

How do I clear and reload the the data in dataTable()?

ajeshviswamanyajeshviswamany Posts: 2Questions: 1Answers: 0
edited March 2018 in Free community support

**1 On load i am loading the data in the data Table, **

$(document).ready(function () {
$('#example').DataTable({
data: currentSelectedPolicyResults.data,
scrollY: '50vh',
columns: [
{ title: "TaskId", data: "TaskId" },
{ title: "Task Description", data: "Task Description" },
{ title: "Status.", data: "Status" }
]
});
setClick();
});

2: How do i clear the data from current table?
3. Then I want to load updated JSON into the same table, How do i do this?

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Have you looked at the ajax examples?

  • ajeshviswamanyajeshviswamany Posts: 2Questions: 1Answers: 0

    i did, I can clear the data using
    var table = $('#example').DataTable();
    table.clear().draw();

    But when i try to load updated JSON its showing this error "DataTables warning: table id=example - Cannot reinitialise DataTable."

    Reload Function : table.rows.add(UpdatedJSON.data);

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945

    Did you follow the troubleshooting steps linked to in the error?
    https://datatables.net/manual/tech-notes/3

    That should point you to the solution.

    Kevin

This discussion has been closed.