即時嘗試循環到數據表表上的所有錶行,但只循環到當前顯示的錶行像我有100個記錄(100錶行)並且目前顯示了10個表格行,不幸的是,它僅循環到10個表格行。datatables遍歷所有錶行,只循環當前顯示的錶行
我用下面的代碼通過各表中的行
$("#admin_user_table tbody tr").each(function(){
alert("yes");
});
任何想法,幫助的線索,意見,建議循環?
下面是我的小提琴更具體。
$(document).ready(function(){
$('#sample_table').DataTable({
"bSort": false,
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
});
$("#test_loop").click(function(){
$("#sample_table tbody tr").each(function(){
alert("table row");
});
});
});
table{width: 100%}table td, table th{padding: 7px; text-align: center; vertical-align: middle}table thead{border-bottom: 2px solid #cccccc;}table tbody tr{border-bottom: 1px solid #ccc;}
<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="test_loop">Loop through all the table rows</button>
,我不覺得有什麼,如果表是動態填充用ajax任何方式...... –
表是不是由ajax @ArunPJohny –
填充,然後如何完成分頁... –