Multi-column sorting: Lock one into ASC

Multi-column sorting: Lock one into ASC

ignignoktignignokt Posts: 146Questions: 4Answers: 39

Right now I am using row grouping. This means when you sort, you see a duplicate of the row grouping header which I find annoying. To fix this, I make each column always sort by the "day" column first which is how they are grouped. This keeps the groups together while sorting, but it also toggles the day column from ASC to DESC or vice versa each time. Is there a way to lock in one column to ASC or DESC? This is an example of what I have:

var day_table = $('#days').DataTable({
    columns:[
        {sTitle:"Day",data:"Day",className:"child",bSortable:false},
        {sTitle:"ID",data:"ID",className:"child",orderData:[0,1]},
        {sTitle:"Username",data:"Username",className:"child",orderData:[0,2]},
        {sTitle:"Favorite Number",data:"Favorite Number",className:"child",orderData:[0,3]}
    ]
});

What I'd basically like to do is pass something like: orderData:[[0,'asc'],[1,'']] meaning column 0 always stays sorted as asc no matter what I do.

I can think of a few "hack" ways of doing it but I was hoping there was a real built in solution.

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    edited December 2014

    In case there is not a built in solution, I just did this in my server-side function as a bad fix.

    if(isset($_REQUEST['order'])){
        array_unshift($_REQUEST['order'],array('column'=>0,'dir'=>'asc'));
    }
    
  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    You could use columns.orderSequence to control the ordering options of a column and potentially lock it to one option only.

    Allan

This discussion has been closed.