gpt4 book ai didi

javascript - 在 TH 中按类排序表

转载 作者:太空宇宙 更新时间:2023-11-04 11:20:32 25 4
gpt4 key购买 nike

我有一个包含 10 列的表,每一列都有不同的类,例如最后一列有:data-tot

如何按类降序排列表格?

一个完整的jsFiddle is available here ,但 HTML 的一小部分看起来像这样(oddeven 行继续用于完整数据)。

<table class="sp-league-table sp-data-table sp-sortable-table sp-scrollable-table sp-paginated-table dataTable no-footer" data-sp-rows="30" id="DataTables_Table_9" role="grid">
<thead>
<tr role="row">
<th class="data-rank sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="Pos">Pos</th>
<th class="data-name sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="Squadra">Squadra</th>
<th class="data-gia sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="GIA">GIA</th>
<th class="data-ros sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="ROS">ROS</th>
<th class="data-gio sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="6GIO">6GIO</th>
<th class="data-giotwo sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="5GIO">5GIO</th>
<th class="data-giothree sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="4GIO">4GIO</th>
<th class="data-giofour sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="3GIO">3GIO</th>
<th class="data-tav sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="TAV">TAV</th>
<th class="data-tot sorting" tabindex="0" aria-controls="DataTables_Table_9" rowspan="1" colspan="1" aria-label="TOT">TOT</th>
</tr>
</thead>
<tbody>
<tr class="odd" role="row">
<td class="data-rank">1</td>
<td class="data-name"><a href="http://www.quartuleague.com/squadra/consulenza-impresa/">CONSULENZA IMPRESA</a></td>
<td class="data-gia">0.5</td>
<td class="data-ros">0</td>
<td class="data-gio">0.5</td>
<td class="data-giotwo">1</td>
<td class="data-giothree">0</td>
<td class="data-giofour">0</td>
<td class="data-tav">0</td>
<td class="data-tot">2.0</td>
</tr>
<tr class="even" role="row">
<td class="data-rank">2</td>
<td class="data-name"><a href="http://www.quartuleague.com/squadra/new-team/">NEW TEAM</a></td>
<td class="data-gia">0.5</td>
<td class="data-ros">2</td>
<td class="data-gio">1.0</td>
<td class="data-giotwo">1</td>
<td class="data-giothree">0</td>
<td class="data-giofour">0</td>
<td class="data-tav">0</td>
<td class="data-tot">4.5</td>
</tr>
</tbody>
</table>

最佳答案

SOLUTION

使用下面的代码按 jQuery 选择器 .data-tot 指定的列对表格进行降序排序。

$('#myTable').DataTable().column('.data-tot').order('desc').draw();

参见 columns().order()了解更多详情。

DEMO

参见 updated jsFiddle用于代码和演示。

关于javascript - 在 TH 中按类排序表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32822902/

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