我试图循环到datatables表上的所有表行,但只是循环到当前显示的表行,就像我有100条记录(100个表行),当前显示10个表行,它只是循环到10个表行不幸。
我在循环遍历每个表行时使用了以下代码
$("#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>
答案 0 :(得分:0)
您可以使用raw filter
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var enabled = $('#my-filter').is(':checked');
return !enabled || /raw$/g.test(data[1]);
}
);
$(document).ready(function() {
var table = $('#sample_table').DataTable({
"bSort": false,
"pagingType": "full_numbers",
"dom": 'T<"clear">lfrtip',
});
$("#my-filter").change(function() {
table.draw();
});
});
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 raw</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 raw</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 raw</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 raw</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 raw</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 raw</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 raw</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 raw</td>
<td>sample branch</td>
<td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td>
<td>Sample raw</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 raw</td>
<td>sample branch</td>
<td>sample department</td>
</tr>
<tr>
<td>Sample Name 1</td>
<td>Sample raw</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>
<input id="my-filter" type="checkbox" />