[英]Datatables in Blazor: Dispose() doesn't work
Following a post on DataTables.net , successfully I added DataTables.net on my Blazor WebAssembly across the application.在DataTables.net上的帖子之后,我成功地将 DataTables.net 添加到了整个应用程序的 Blazor WebAssembly 上。 The problem I'm facing is when I change page.
我面临的问题是当我更改页面时。 As you can see in the following image, for each page with DataTables.net I change, I still have the search bar from the previous page.
正如您在下图中看到的,对于我更改的 DataTables.net 的每个页面,我仍然拥有前一页的搜索栏。
In the code of each page I added在我添加的每个页面的代码中
public void Dispose()
{
JSRuntime.InvokeAsync<bool>("DataTablesRemove", "#tableData");
}
DataTablesRemove
is defined in the index.html
DataTablesRemove
在index.html
中定义
function DataTablesRemove(table) {
$(document).ready(function () {
$(table).DataTable().destroy();
// Removes the datatable wrapper from the dom.
var elem = document.querySelector(table + '_wrapper');
elem.parentNode.removeChild(elem);
});
}
How can I fix this issue?我该如何解决这个问题?
You have to add @implements IDisposable
to the top of your page/component.您必须将
@implements IDisposable
添加到页面/组件的顶部。
Otherwise Dispose() is just a method that won't be called.否则 Dispose() 只是一个不会被调用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.