gpt4 book ai didi

javascript - 单击按钮时显示数据表表中的所有记录

转载 作者:搜寻专家 更新时间:2023-11-01 04:56:44 25 4
gpt4 key购买 nike

当我单击 ID 为“show_all_records”的按钮时,如何显示所有记录的任何想法和线索?如果我单击 ID 为“restore_records”的按钮,数据表将恢复为默认状态,例如记录被设置回默认状态。

我可以使用“paging: false/true”,但我不知道如何以实时方式应用它。

$(document).ready(function(){

$('#sample_table').DataTable( {
"bSort": false,
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
});


});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/r/dt/dt-1.10.8/datatables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/r/dt/dt-1.10.8/datatables.min.js"></script>



<table cellpadding="0" cellspacing="0" id="sample_table">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Branch</th>
<th>Department</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td><td>Sample position</td><td>sample branch</td><td>sample department</td>
</tr>
</tbody>
</table>

<button id="show_all_records">show all records</button>
<button id="restore_records">Restore records on its default state</button>

最佳答案

dataTables 提供了各种函数来实现这一点。所以下面是你如何做到这一点的方式。检查内联评论以获取更多信息:

DEMO

var oTable; //global variable to hold reference to dataTables
var oSettings; //global variable to hold reference to dataTables settings

$(document).ready(function(){
oTable=$('#sample_table').DataTable( {
"bSort": false,
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
}); //store reference of your table in oTable
oSettings = oTable.settings(); //store its settings in oSettings
});

$("#show_all_records").on('click',function(){
oSettings[0]._iDisplayLength = oSettings[0].fnRecordsTotal();
//set display length of dataTables settings to the total records available
oTable.draw(); //draw the table
});

$("#restore_records").on('click',function(){
oSettings[0]._iDisplayLength=10;
//set it back to 10
oTable.draw();//again draw the table
});

关于javascript - 单击按钮时显示数据表表中的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32241586/

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