How Can I Refresh A JQuery DataTable Without Making A Database Call?

Asked 3 months ago
Answer 1
Viewed 31
1

 The DataTable API lets you update a jQuery DataTable's data or status without executing a database query. These are a few techniques:

1. Clear and Add Data: Clear the current data and then add fresh data if you wish to update the table with more information without requesting server access.

table.clear().rows.add(newData).draw();

NewData here is a set of data you wish to show.

2. Redraw the Table: Simply redraw the table if you changed the data array of the table and must reflect such changes.

table.draw();

3, Reload Data from a Local Source: Should you have a local data source that needs to be reloaded into the table, the ajax.reload() approach can be used should your Data Table have AJAX source initialization. If you don't need to get fresh data from the server, you can utilize it with an empty source or a fictitious URL.

table.ajax.url('path/to/your/local/source').load();

4. Reset the Table: You may destroy and reinitialize the DataTable to return it to its starting state (with the initial data).

table.destroy(); $('#example').DataTable({ // Your initialization options });

Every technique has varied uses; so, pick the one that most suits your situation.

Related: How to display data from database in HTML table using Python?

Answered 3 months ago Anonymous Anonymous