I am trying to implement functionality whereby clicking a button on the screen will cause my jQuery dataTable to refresh (as the server-side data source may have changed since the dataTable was created).
Here's what I have:
$(document).ready(function() {
$("#my-button").click(function() {
$("#my-datatable").dataTable().fnReloadAjax();
});
});
But when I run this, it does nothing. What's the proper way to refresh the dataTable when the button is clicked? Thanks in advance!
Destroy the datatable first and then draw the datatable.
HTML
Javascript
Source
This is how I do it... Maybe not the best way, but it's definitely simpler (IMHO) and doesn't require any additional plugins.
HTML
jQuery
Note: In my workings with jQuery dataTable, sometimes if you don't have
<thead></thead><tbody></tbody>
it doesn't work. But you might be able to get by without it. I haven't exactly figured out what makes it required and what doesn't.i would recommend using the following code.
The reason for this, user paging will not be reset on reload.
Example:
detail about this can be found at Here
reinitialise datatable with init and write retrieve as true ..done..so simple
eg.