How to use Absolute sorting but also sort rows underneath by differnt column

How to use Absolute sorting but also sort rows underneath by differnt column

ernie999ernie999 Posts: 5Questions: 2Answers: 0
edited September 2021 in Plug-ins

Hello, I'm trying to use the Sorting with Absolute Position plugin to keep a value pinned to the top of the page (works fine) but everything underneath those row I'd like to sort by a different column.

For example in this jsfiddle: https://jsfiddle.net/Ernesto1/4mdogv2a/
the rows with London as the office are pinned to the top but all rows underneath I'd like to sort by age (desc).

However, when I sort the age row I lose the sorting in the office row. Any ideas how I could accomplish this would be greatly appreciated.

This works:

$(document).ready(function() {
    var dispType = $.fn.dataTable.absoluteOrder({
        value:'London', position:'top'
    });
    
    var table = $('#example').DataTable({       
        "columnDefs" : [
        { targets: 2, type: dispType }
    ],
    order: [[2, 'desc']]
    });
    
});

But of course changing the order line like this results in the London rows no longer being pinned to the top.

order: [[3, 'desc']]

thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    You could use orderFixed alongside the Absolute plugin, and fix a hidden column, something like this. Without the hidden column, the entire Office column would get sorted too (see here) which is probably not what you want,

    Colin

  • ernie999ernie999 Posts: 5Questions: 2Answers: 0

    Great, works like a charm! Thank you!

Sign In or Register to comment.