I'm using the jquery DataTables plugin. From their documentation:
If sorting is enabled, then DataTables will perform a first pass sort on initialisation. You can define which column(s) the sort is performed upon, and the sorting direction, with this variable. The aaSorting array should contain an array for each column to be sorted initially containing the column's index and a direction string ('asc' or 'desc').
Is it possible to have sorting enabled but disable this first pass sort on initialization? I am currently doing the initial sort server side and need sorting functionality but don't need this initial sort functionality.
The ability to order data can be disabled using this option. Note that the ability to add or remove sorting of individual columns can be disabled by the columns. orderable option for each column. This parameter is a global option - when disabled, there are no sorting actions applied by DataTables at all.
Use columnDefs option to remove sorting from a column. Pass column index in targets within [] (Indexing starting from 0) and set orderable to false . In the example, I removed sorting from email and salary column.
You need to change the properties of the GridView then, not the DataTable. The GridView data is the thing getting sorted in this case, not the DataTable. @KevenDenen I already tried that. "AllowUserToOrderColumns" is False, and clicking it still sorts the data.
Well I found the answer set "aaSorting" to an empty array:
$(document).ready( function() {
$('#example').dataTable({
/* Disable initial sort */
"aaSorting": []
});
})
For newer versions of Datatables (>= 1.10) use order option:
$(document).ready( function() {
$('#example').dataTable({
/* No ordering applied by DataTables during initialisation */
"order": []
});
})
As per latest api docs:
$(document).ready(function() {
$('#example').dataTable({
"order": []
});
});
More Info
Try this:
$(document).ready( function () {
$('#example').dataTable({
"order": []
});
});
this will solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With