I've been trying to figure this out now for a few hours and its not happening. When I load my table I need for it to sort desc on the first col. Here's what I have but no luck.
/**
* Makes the table in the tabs for reports
*
* @param array Holds the data for datatable.
**/
var makeTabTable = function(tableData){
$("#tab_active_reg").dataTable({
bJQueryUI : true,
bDestroy : true,
aoColumns : [
{"sTitle" : "Seen", "sWidth" : "50px", "asSorting": [ "desc"]},
{"sTitle" : "Sold", "sWidth" : "50px"},
{"sTitle" : "Name", "sWidth" : "240px"}
],
aaData : tableData
});
$('.tabsComponent').find('.fg-toolbar').empty();
};
Using the order initialisation parameter, you can set the table to display the data in exactly the order that you want. The order parameter is an array of arrays where the first value of the inner array is the column to order on, and the second is 'asc' (ascending ordering) or 'desc' (descending ordering) as required.
Use columnDefs option to remove sorting from a column. Pass column index in targets within [] (Indexing starting from 0) and set orderable to false .
targets option provides the information required by DataTables for which columns in the table the column definition object should be applied. It can be: 0 or a positive integer - column index counting from the left. A negative integer - column index counting from the right.
just add this option to the dataTable()
call:
aaSorting : [[0, 'desc']]
so in your case:
$("#tab_active_reg").dataTable({
bJQueryUI : true,
bDestroy : true,
aaSorting : [[0, 'desc']],
aoColumns : [
{"sTitle" : "Seen", "sWidth" : "50px"},
{"sTitle" : "Sold", "sWidth" : "50px"},
{"sTitle" : "Name", "sWidth" : "240px"}
],
aaData : tableData
});
as you can see, it is an array of [colnumber, sortdirection]
, so you can specify multiple.
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