gpt4 book ai didi

html - 如何对数据表中的特定列进行排序?

转载 作者:行者123 更新时间:2023-11-28 04:35:52 25 4
gpt4 key购买 nike

我正在使用 Datatables 来打印 HTML 表格,在这里我遇到了类似的问题:

表是动态创建的(使用 while 循环打印),因此我不知道它会有多少列。之后,我在

上应用了数据表
$('#table').dataTable( {
"bDestroy":true,
"sScrollY": temp_fh,
"bPaginate": false,
"bScrollCollapse": true,
"bProcessing": true,
"bFilter":true,
"bSort":true,
});

那么现在如何只对第二列应用排序?

因为我从 Datatables 引用了 bSortable这允许我们禁用特定列的排序,但在这种情况下,我们不知道表中有多少列。

谢谢。

最佳答案

这个怎么样?

$('#table').dataTable( {
"bDestroy":true,
"sScrollY": temp_fh,
"bPaginate": false,
"bScrollCollapse": true,
"bProcessing": true,
"bFilter":true,
"bSort":true,
aoColumnDefs: [
{ aTargets: [ '_all' ], bSortable: false },
{ aTargets: [ 0 ], bSortable: true },
{ aTargets: [ 1 ], bSortable: true }
]

更新

好的,覆盖 _all 似乎是不可能的。也许你可以在你的 while 循环中像这样通过 css 禁用对列的排序:

<th class="no-sort">

并使用这个初始化代码:

// Disable sorting on the no-sort class
"aoColumnDefs" : [ {
"bSortable" : false,
"aTargets" : [ "no-sort" ]
} ]

参见:disable a column sorting using jquery datatables

关于html - 如何对数据表中的特定列进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20086956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com