default ordering false in datatable
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:
$(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:
$(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.