简体   繁体   English

jQuery DataTables持久性主要排序

[英]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? jquery DataTables 1.10.1中是否有一种方法始终对隐藏的列进行主排序,而不考虑用户单击要对哪些可见列进行排序?

The spec is to always have primary sort on a numeric groupsortkey in asc order. 规范应始终以升序对数字groupsortkey进行主排序。 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. 目的是始终将具有相同groupsortkey行聚集在一起,而不分散分布,无论用户要对其他可见列进行排序。

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 . 在下面的代码段中, id="taskViewer"的元素是一个有效的html表,其中包含十列,其中第一列将被隐藏并用作groupsortkey

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

Have a look at the orderFixed option. 看一下orderFixed选项。 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. 在这种情况下,0列将是主要排序,然后用户选择的排序是次要排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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