简体   繁体   English

使用DataTables按列对表进行排序

[英]Sort table by a column with DataTables

I'm trying to sort a table by a particular column with DataTables, but I receive this warning: 我正在尝试使用DataTables按特定列对表进行排序,但是收到此警告:

DataTables warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. DataTables警告:表ID = DataTables_Table_0-无法重新初始化DataTable。 For more information about this error, please see http://datatables.net/tn/3 有关此错误的更多信息,请参见http://datatables.net/tn/3

I put these scripts but maybe I'm doing something wrong: 我放了这些脚本,但也许我做错了什么:

jQuery('.sp-template-league-table table').DataTable({ paging: false, searching: false, info: false, retrieve: true });

jQuery('.sp-template-league-table table').DataTable().column('.data-tot').order('asc').draw();

You can see the table in this page: http://www.quartuleague.com/goldcup-2015-girone-gold/ 您可以在此页面中查看表格: http : //www.quartuleague.com/goldcup-2015-girone-gold/

under the "Fair Play" Tab, i want to sort table by "TOT" 在“公平竞赛”标签下,我想按“ TOT”对表格进行排序

If you want to sort the data by default you can also pass along additional parameters on the initialization instead of using .draw() : 如果要默认对数据进行排序,则还可以在初始化时传递其他参数,而不是使用.draw()

Example: Ascending sorting of the 4th column (indices start at 0) 示例:对第4列进行升序排序(索引从0开始)

$('#example_table').DataTable( {
    "order": [[ 3, "asc" ]]
} );

In your case you need to add the column number of your data-tot column (8 or -1) like so: 在您的情况下,您需要添加data-tot列的列号(8或-1),如下所示:

jQuery('.sp-template-league-table table').DataTable({ 
order: [[ 8, "asc" ]],
paging: false, 
searching: false, 
info: false, 
retrieve: true 
});

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

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