简体   繁体   English

如何从 html 代码重新加载 DataTable

[英]How to reload DataTable from html code

here's my question, I've got a datatable in html, I have a function replacing the html code of the datatable by an updated one (the same, but with the update database values).这是我的问题,我有一个 html 数据表,我有一个函数用更新的数据表替换数据表的 html 代码(相同,但更新数据库值)。

But the probleme is, things like "Display 1 entry from 1 to 1" doesn't update.但问题是,诸如“从 1 到 1 显示 1 个条目”之类的内容不会更新。

I'd like to refresh the whole tab with the new values, and with the data-table functions from.我想用新值和数据表函数刷新整个选项卡。

Any ideas ?有任何想法吗 ?

I'm not really clear about how my code is;我不太清楚我的代码是怎样的; but basically : it's a html table ruled by php's foreach/if and echoes of values got by requesting a database.但基本上:它是一个 html 表,由 php 的 foreach/if 和通过请求数据库获得的值的回声控制。 So, even while reloading the same html code, there won't be the same values if you add something through the database.因此,即使在重新加载相同的 html 代码时,如果您通过数据库添加某些内容,也不会有相同的值。

I'll add the fact that there is switchbuttons inside the data-base, and they get also destroy by the html reload.我将添加一个事实,即数据库中有开关按钮,并且它们也会被 html 重新加载破坏。 When I say html reload, I mean this : $('#myTable').html(new_html);当我说 html 重新加载时,我的意思是: $('#myTable').html(new_html);

Thank you谢谢

Assign your datatable initialize to variable like below将您的数据表初始化分配给如下变量

var table = $('#myTable').DataTable();

Then whenever you call your function for table reload make sure you call this function after it finish to run.然后,每当您调用表重新加载函数时,请确保在它完成运行后调用此函数。 It is used by datatable to refresh table.数据表使用它来刷新表。

table.draw();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM