简体   繁体   中英

Jquery DataTables Persistent Primary Sort

Is there a way in jquery DataTables 1.10.1 to always do a primary sort on a hidden column regardless of what visible columns the user clicks to sort on?

The spec is to always have primary sort on a numeric groupsortkey in asc order. The aim is to always have rows with the same groupsortkey clustered together and not dispersed regardless of what other visible column the user wants to sort on.

In the snippet below, the element with id="taskViewer" is a valid html table with ten columns, the first of which will be hidden and serve as the groupsortkey .

 var taskViewer = $("#taskViewer").dataTable({
                "columnDefs": [{
                    "targets": [0],
                    "visible": false,
                    "searchable": false }],
                });

Have a look at the orderFixed option. It allows you to do pre or post user sorting.

$('#example').dataTable( {
    "orderFixed": {
        "pre": [ 0, 'asc' ]
    }
} );

In this scenario, the 0 column will be the primary sort and then the user selected sort is secondary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM