Datatables reInitialization (jQuery)

2020-03-01 09:40发布

When I load my page in first place there nothing in the table and the datatable is not initializated, after a few interactions rows are added and when all rows are added (with ajax calls) I init the datatable this way:

oTable = $('#table).dataTable( {
            "bJQueryUI": true,
            "bSortClasses": false,
            "sDom":'T<"clear">',
            "sPaginationType": "full_numbers",
            "sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>'
        } );

The problem is I want to be able to clear that table and keep on adding stuff in the html and then reInit the table from that source code without using fnAddData.

Any ideas?

Thank you!

5条回答
ら.Afraid
2楼-- · 2020-03-01 10:03

Can you use fnUpdate and fnClearTable? http://datatables.net/api

查看更多
Lonely孤独者°
3楼-- · 2020-03-01 10:07

Calling $('#table').dataTable().fnDestroy(); will clear the table of dataTable code and allow you to manipulate the table, and then call dataTable on it again.

查看更多
\"骚年 ilove
4楼-- · 2020-03-01 10:07

When you initialize the datatable set bDestroy: true and before adding the update clear table via $('#myTable').dataTable().fnClearTable();. Thats it!!

查看更多
该账号已被封号
5楼-- · 2020-03-01 10:11

use the initialization variable bDestory. Not nDestroy.

查看更多
The star\"
6楼-- · 2020-03-01 10:21

to clear the table, oTable.api().clear().draw();

to reload data from ajax, oTable.api().ajax.reload();

I don't think reInit is a good manner

查看更多
登录 后发表回答