gpt4 book ai didi

javascript - 如何对数据表进行排序?

转载 作者:行者123 更新时间:2023-11-28 18:48:32 25 4
gpt4 key购买 nike

我需要按“与剩余联系人”列对下面的数据表进行排序,但仅限于小括号之前的数字。

这是我的代码:

var oTable = $('#customers-list').dataTable({});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<table id="customers-list" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Total
<br>contacts</th>
<th>Contacts with
<br>the remaining</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test1</td>
<td class="text-center">11</td>
<td class="text-center">7 (63.64%)</td>
</tr>
<tr>
<td>Test2</td>
<td class="text-center">25</td>
<td class="text-center">14 (56%)</td>
</tr>
<tr>
<td>Test3</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
<tr>
<td>Test4</td>
<td class="text-center">24</td>
<td class="text-center">3 (12.5%)</td>
</tr>
<tr>
<td>Test5</td>
<td class="text-center">24</td>
<td class="text-center">20 (83.33%)</td>
</tr>
<tr>
<td>Test6</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
<tr>
<td>Test7</td>
<td class="text-center">24</td>
<td class="text-center">22 (91.67%)</td>
</tr>
<tr>
<td>Test8</td>
<td class="text-center">24</td>
<td class="text-center">22 (91.67%)</td>
</tr>
<tr>
<td>Test9</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
<tr>
<td>Test10</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
<tr>
<td>Test11</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
<tr>
<td>Test12</td>
<td class="text-center">0</td>
<td class="text-center">0 (0%)</td>
</tr>
<tr>
<td>Test13</td>
<td class="text-center">24</td>
<td class="text-center">24 (100%)</td>
</tr>
</tbody>
</table>

最佳答案

数据顺序数据排序可以做到这一点

you can do like this
<td class="text-center" data-order="14">14 (56%)</td>

了解更多

https://datatables.net/examples/advanced_init/html5-data-attributes.html

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

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