Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery-datatables multi-column sort direction

Using jquery-datatables.

Example: http://jsfiddle.net/b2fLye17/17/

$('#example').DataTable({

    filter:false,
    columnDefs: [
                    {
                        targets: [1],//when sorting age column
                        orderData: [1,2] //sort by age then by salary
                    } 
                ]
});

When you click the age column, The table sort by age ascending then by salary ascending.

What would be my options to make it sort by age ascending then by salary descending ?

Thanks !

-------------------------- Edit 1 ---------------------

Clarification : When the age column is sorted ascending it should sort by age ascending then by salary descending. When the age column is sorted descending it should sort by age descending then by salary ascending

-------------------------- Edit 2 ---------------------

A picture of the desired resultenter image description here

like image 237
sebmoi Avatar asked Dec 17 '14 13:12

sebmoi


1 Answers

Use

$(document).ready(function() {

    $('#example').DataTable({

        filter:false,
        columnDefs: [
                        {
                            orderData: [[1, 'asc'], [2, 'desc']]//sort by age then by salary
                        }
                    ]
    });
});

JS Fiddle http://jsfiddle.net/b2fLye17/13/

like image 153
fly_ua Avatar answered Oct 13 '22 01:10

fly_ua