在dataTables.js jQuery插件中使列不可移植

hd.*_*hd. 18 jquery jquery-plugins datatables

我正在使用dataTables.js jQuery插件.

我的表的第一列是行计数器,所以我不希望它被用户排序.最后一列包含一些用户可以在一行上执行的操作链接.如何使这两列无法使用?

注意:我正在使用数据表的管道(服务器端进程)模式.

sie*_*ppl 12

这是通过将bSortable设置为false 来完成的:

/* Using aoColumnDefs */
$(document).ready(function() {
    $('#example').dataTable( {
        "aoColumnDefs": [ 
            { "bSortable": false, "aTargets": [ 0 ] }
        ] } );
} );

/* Using aoColumns */
$(document).ready(function() {
    $('#example').dataTable( {
        "aoColumns": [ 
            { "bSortable": false },
            null,
            null,
            null,
            null
        ] } );
} );
Run Code Online (Sandbox Code Playgroud)


Jer*_*nch 8

DataTables 1.10+还支持HTML5 data-样式属性,包括data-sortable="false",这使得列不符合排序条件:

<table>
    <thead>
        <tr>
            <th data-sortable="false">Row</th>
            <th>Name</th>
            <th>Join Date</th>
            <th>Organization</th>
            <th data-sortable="false">Options</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            [etc]
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

在jsFiddle中查看此演示


Lar*_*bar 3

aa排序固定

此参数与 aaSorting 参数基本相同,但不能通过用户与表的交互来覆盖。这意味着您可以有一个列(可见或隐藏),始终首先强制对其进行排序 - 之后的任何排序(来自用户)将根据需要执行。这对于将行分组在一起很有用。

使用示例:

$(document).ready( function() {
    $('#example').dataTable( {
         "aaSortingFixed": [[0,'asc'],[5,'asc']]
    } );
} );
Run Code Online (Sandbox Code Playgroud)

0是“不可排序”行的编号(从左开始)。(所以在该示例中,第一列和第六列是固定的)

官方文档