I have a 4 column table, I want the first 3 columsn to be sortable by the user, but not the 4th, this is working fine. I also want the 3rd column to sort in ASC order by default. This part isn't working, I cant get any of the columns to sort by default and can't figure out what's wrong with my syntax:
$(document).ready(function() {
$(".table-sortable").dataTable({
aaSorting: [],
bPaginate: false,
bFilter: false,
bInfo: false,
bSortable: true,
bRetrieve: true,
aoColumnDefs: [
{ "aTargets": [ 0 ], "bSortable": true },
{ "aTargets": [ 1 ], "bSortable": true },
{ "aTargets": [ 2 ], "asSorting": [ "asc" ], "bSortable": true },
{ "aTargets": [ 3 ], "bSortable": false }
]
});
});
Here's what I've been working from: http://datatables.net/usage/columns
This should get you what you need
$(document).ready(function() {
$(".table-sortable").dataTable({
aaSorting: [[2, 'asc']],
bPaginate: false,
bFilter: false,
bInfo: false,
bSortable: true,
bRetrieve: true,
aoColumnDefs: [
{ "aTargets": [ 0 ], "bSortable": true },
{ "aTargets": [ 1 ], "bSortable": true },
{ "aTargets": [ 2 ], "bSortable": true },
{ "aTargets": [ 3 ], "bSortable": false }
]
});
});
The key is the aaSorting
option. For some reason it's not in his 'main' Usage pages... you can find it here though http://datatables.net/ref
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