Jowin / Datatables-Bootstrap3

Plugin for Datatables Bootstrap3 UI Compatibility
215 stars 82 forks source link

Default sorting not working #7

Closed aljazstraser closed 10 years ago

aljazstraser commented 10 years ago

Hi,

From jquery.Datatables.. definition:

This works after clicking on one column header, but initialized table is always sorted by first column asceding.

How to override this so initializing sorting would be descending.

I also tried with

"asSorting": [ 'asc', 'desc' ] to "asSorting": [ 'desc, 'asc' ]

but no go.

Thanks in advance.

BR

silentsno commented 10 years ago

I can change the default sort. example:

$('#my_table').dataTable( {
        "aaSorting": [[ 6, "asc" ]] // column #7 sorted (zero indexed)
    } );
aljazstraser commented 10 years ago

Thanks man. I was trying same but with different syntax. Now initialized sorting by first column is descending.

silentsno commented 10 years ago

No problem. Glad its working for you.

Jayesh1992Patil commented 5 years ago

Hello, I am also facing same issue. There are some hidden header also in table and index I have mentioned original index in function(sortTablebystatus) and if we does not count hidden headers then it's position is 10 & 4 respectively. Please help me.

function sortTablebystatus(status,tabledata){ $('#example').DataTable().clear().destroy();

var sortorder = [[46,'desc']]; if(status==="bydate") { sortorder = [[46,'desc']]; sortTable('#example',sortOrder,tabledata); } else { sortorder = [[30,'desc']] sortTable('#example',sortOrder,tabledata); } };

function sortTable(tableid,sortOrder,tabledata) { this.data = tabledata; setTimeout(function(){ $(tableid).DataTable({ searching: true, iDisplayLength: 25, "aaSorting": sortOrder, buttons: [{ extend: 'csv', text: ' ', titleAttr: 'csv', footer: false //, exportOptions: {columns: [0, 1, 2, 3, 4, 5, 6, 7, 8]} }, { extend: 'excel', text: ' ', titleAttr: 'excel', footer: false //, exportOptions: {columns: [0, 1, 2, 3, 4, 5, 6, 7, 8]} }, { extend: 'print', text: ' ', titleAttr: 'print', footer: false //, exportOptions: {columns: [0, 1, 2, 3, 4, 5, 6, 7, 8]} }] } ); $("

").insertBefore($(tableid)); },500) }