Skip to content
the poor coder

reload datatable without ajax

Poor Man
Published
Reading time
1 min read
On this page

How to Reload Datatable without AJAX#

If you are using Datatable to display data on your website, you may come across a situation where you need to reload the table without using AJAX. This can be useful in situations where you do not want to make a server call every time the table needs to be refreshed.

Method 1: Refresh the Page#

The easiest way to reload the datatable without AJAX is to simply refresh the page. This will reload the entire page, including the datatable. However, this method is not ideal if you have other data or user input on the page that you do not want to lose.

Method 2: Use Datatable API#

Datatable provides an easy-to-use API that allows you to manipulate the table data and refresh it as needed. To reload the datatable using API, you can use the following code:

JavaScript

var table = $('#example').DataTable();
table.clear().draw();
table.rows.add(data).draw();
  • The first line initializes the datatable.
  • The second line clears the existing data from the table.
  • The third line adds new data to the table.
  • The fourth line redraws the table with the new data.

This method allows you to refresh the datatable without making a server call, making it faster and more efficient than reloading the entire page.

Method 3: Use Built-in Datatable Functionality#

Datatable provides built-in functionality that allows you to refresh the table without using AJAX. You can use the following code to refresh the datatable:

JavaScript

$('#example').DataTable().ajax.reload();

This code will reload the datatable using the current data source. If you have made any changes to the data source, they will be reflected in the table after it is reloaded.

Conclusion#

There are several ways to reload the datatable without using AJAX. The method you choose will depend on your specific needs and requirements. Whether you choose to refresh the page, use the Datatable API, or use built-in functionality, you can easily refresh your table data without making a server call.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC