datatables 遍历所有 table 行,只在当前显示的 table 行上循环

datatables loop through all table rows, only did loop on the currently shown table rows

我试图循环到数据 table 上的所有 table 行 table 但只循环到当前显示的 table 行,就像我有 100 条记录( 100 table 行)和当前显示 10 table 行,不幸的是它只循环到 10 table 行。

我使用下面的代码循环遍历每个 table 行

$("#admin_user_table tbody tr").each(function(){
    alert("yes");
});

有什么想法、帮助、线索、建议、建议吗?

下面是我的 fiddle 更具体一些。

$(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>

您可以使用 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" />