How to redraw DataTable with new data

前端 未结 7 435
感动是毒
感动是毒 2020-12-13 08:45

I have checked several questions already about this topic here in stackoverflow, but they are all using the old dataTable. I am using DataTable. I populated my DataTable by

相关标签:
7条回答
  • 2020-12-13 09:08

    I was having same issue, and the solution was working but with some alerts and warnings so here is full solution, the key was to check for existing DataTable object or not, if yes just clear the table and add jsonData, if not just create new.

                var table;
                if ($.fn.dataTable.isDataTable('#example')) {
                    table = $('#example').DataTable();
                    table.clear();
                    table.rows.add(jsonData).draw();
                }
                else {
                    table = $('#example').DataTable({
                        "data": jsonData,
                        "deferRender": true,
                        "pageLength": 25,
                        "retrieve": true,
    

    Versions

    • JQuery: 3.3.1
    • DataTable: 1.10.20
    0 讨论(0)
提交回复
热议问题