jQuery 禁用数据表中的排序不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8662062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disabling sorting in datatables not functioning
提问by aport002
Here is the code i am using
这是我正在使用的代码
oTable = $('#example').dataTable({
"bSort": false,
"bStateSave":true,
"aoColumns": [
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false } ]
});
The problem i'm having is that the table starts off blank and its populated by user input. Once the user starts to input things into the table, it sorts them by product ID. I'm trying to remove this sorting so that it just lists them as they are input.
我遇到的问题是表格以空白开始,并由用户输入填充。一旦用户开始向表中输入东西,它就会按产品 ID 对它们进行排序。我正在尝试删除这种排序,以便它只在输入时列出它们。
EDIT: I have come to the conclusion that NONE of my initialization settings are working. I believe it has to do with the fnAddRow when the table is empty except for headers.
编辑:我得出的结论是,我的初始化设置均无效。我相信它与 fnAddRow 当表为空时(标题除外)有关。
EDIT2: I've isolated it down to the fnAddData. When I initialize the table with trash data everything is formatted as its supposed to be but then once i use the fnAddData, it removes all formating
EDIT2:我已将其隔离到 fnAddData。当我用垃圾数据初始化表时,所有内容都按预期格式化,但是一旦我使用 fnAddData,它就会删除所有格式
回答by Alborz
Try this:
尝试这个:
$(document).ready( function () {$('#example').dataTable( {
"bSort": false
} );
}
回答by Daniel
try this:
尝试这个:
this is to disable initial sort
这是禁用初始排序
$(document).ready( function() {
$('#example').dataTable({
"aaSorting": []
});
})
回答by roNn23
Since version 1.10
of DataTables, you can use the following option to disable the ordering completely:
自1.10
DataTables版本以来,您可以使用以下选项完全禁用排序:
$('#dataTable').dataTable({
ordering: false
});
回答by Allan Jardine
bSort ( http://datatables.net/ref#bSort) is the correct way to disable sorting in DataTables. Perhaps you can link to your example which shows sorting still enabled with this parameter set please?
bSort ( http://datatables.net/ref#bSort) 是在 DataTables 中禁用排序的正确方法。也许您可以链接到您的示例,该示例显示使用此参数集仍启用排序?
回答by Bhargav Kaklotara
try this one,
试试这个,
set data-orderable ="false" in the table header tag
在表头标签中设置 data-orderable="false"
<table id="orders">
<thead>
<tr>
<th data-orderable="false">ID</th>
<th>Customer Name</th>
<th data-orderable="false">Total</th>
<th>Date</th>
<th data-orderable="false">Action</th>
</tr>
</thead>
</table>
回答by Kailas
use the below code
使用下面的代码
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] }
] } );
OR use the link http://datatables.net/ref#bSortable
回答by Scherbius.com
Default sorting can be set by asSortingparameter. Please see:
默认排序可以通过asSorting参数设置。请参见: