Datatables in Blazor: Dispose() doesn't work
Datatables in Blazor: Dispose() doesn't work
erossini
Posts: 4Questions: 3Answers: 0
in DataTables
Following a post on DataTables.net, successfully I added DataTables.net on my Blazor WebAssembly across the application. 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.
In the code of each page I added
public void Dispose()
{
JSRuntime.InvokeAsync<bool>("DataTablesRemove", "#tableData");
}
DataTablesRemove
is defined in the 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?
This discussion has been closed.
Answers
I forgot to add at the top of the page
Does it work if you do:
At the moment you are running the function and then waiting for document ready. I don't know if Blazor fires that multiple times inside a single page does it?
Allan