gpt4 book ai didi

javascript - 按首选条件在表中显示第一个或最上面的记录

转载 作者:行者123 更新时间:2023-12-02 15:06:48 25 4
gpt4 key购买 nike

有没有办法可以首先显示表中具有“BRANCH 1”“分支”的记录?有什么想法吗,请帮忙?下面是我的片段。

$(document).ready(function(){
$("#dtable").DataTable( {
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
"lengthMenu": [[10, 25, 50, -1],[10, 25, 50, "All"]],
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<table id="dtable" class="table table-hover">
<thead>
<tr>
<th>NAME</th>
<th>BRANCH</th>
</tr>
</thead>
<tbody>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
</tbody>
</table>

最佳答案

您需要使用数据表的默认排序更多信息可以在此处找到: https://datatables.net/examples/basic_init/table_sorting.html

基本上你只需要"order": [[ 1, "asc"]]

演示:

$(document).ready(function(){
$("#dtable").DataTable( {
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
"lengthMenu": [[10, 25, 50, -1],[10, 25, 50, "All"]],
"order": [[ 1, "asc" ]]
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<table id="dtable" class="table table-hover">
<thead>
<tr>
<th>NAME</th>
<th>BRANCH</th>
</tr>
</thead>
<tbody>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 2</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 3</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
<tr>
<td>NAME 1</td><td>BRANCH 1</td>
</tr>
</tbody>
</table>

关于javascript - 按首选条件在表中显示第一个或最上面的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076691/

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