Skip to content
the poor coder

default ordering false in datatable

Poor Man
Published
Reading time
1 min read
On this page

Default Ordering False in DataTable#

If you are working with DataTables, you may have come across the term "default ordering false". This means that you do not want DataTables to automatically sort your table when it loads.

By default, DataTables will sort your table based on the first column in ascending order. However, if you have a specific sorting order in mind or you simply do not want DataTables to sort your table at all, you can use the "default ordering false" option.

Using Default Ordering False#

To use default ordering false, you simply need to add the following code to your DataTable initialization:

Text
$(document).ready(function() {
  $('#example').DataTable({
    "order": []
  });
});

In this example, we are initializing a DataTable on a table with the ID "example". The "order" option is an array that specifies the column(s) to sort by. Since we want to disable sorting, we simply leave the array empty.

Alternatively, you can use the following code:

Text
$(document).ready(function() {
  $('#example').DataTable({
    "ordering": false
  });
});

This accomplishes the same thing as the previous example. The "ordering" option is a boolean that enables or disables sorting. In this case, we are disabling sorting by setting it to false.

Conclusion#

Using "default ordering false" in DataTables is a simple way to disable automatic sorting of your table. Whether you choose to use the "order" option or the "ordering" option, both methods will accomplish the same thing.

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