数据表重新初始化 (jQuery)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3207472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:01:38  来源:igfitidea点击:

Datatables reInitialization (jQuery)

jqueryajaxinitializationdatatables

提问by Pierluc

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:

当我首先加载我的页面时,表中没有任何内容并且数据表未初始化,在添加了一些交互行之后,当添加了所有行(使用 ajax 调用)时,我以这种方式初始化数据表:

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.

问题是我希望能够清除该表并继续在 html 中添加内容,然后在不使用 fnAddData 的情况下从该源代码重新初始化该表。

Any ideas?

有任何想法吗?

Thank you!

谢谢!

回答by shmuel613

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

调用$('#table').dataTable().fnDestroy();将清除dataTable代码表并允许您操作该表,然后dataTable再次调用它。

回答by Aaron Harun

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

你能用fnUpdatefnClearTable吗?http://datatables.net/api

回答by user2098333

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

当您初始化数据表集 bDestroy: true 并通过添加更新清除表之前$('#myTable').dataTable().fnClearTable();。就是这样!!

回答by Gutzofter

use the initialization variable bDestory. Not nDestroy.

使用初始化变量bDestory。不是nDestroy

回答by isoloist

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

清除表格,oTable.api().clear().draw();

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

从ajax重新加载数据,oTable.api().ajax.reload();

I don't think reInit is a good manner

我不认为 reInit 是一种好方式