【发布时间】:2016-12-08 21:44:57
【问题描述】:
我正在使用引导数据表并制作了一个自定义过滤器。我想按值过滤所有动物。例如:
如果我选择“猫”,则只显示具有“猫”类的行。
到目前为止它正在工作,但是当我选择另一种动物时,我无法弄清楚如何再次重置已删除的行。有一次我的行不见了,我就无法挽回了。
var table = $('.data-table').DataTable({
"dom": "<'row'<'col-sm-4'l><'col-sm-4'f><'col-sm-4 customFilterHolder'>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
"scrollX": true,
initComplete: function(){
$(".customFilterHolder").html('<div style="float:right;min-width:200px"><div style="float:right;"><select name="select" class="select form-control select2" style="width: 100%;"><option value="all">All</option><option value="dog">Dog</option><option value="cat">Cat</option><option value="horse">Horse</option></select></div><div style="float:right;margin:4px 10px 10px">Filter</div></div>');
$('.select').on('change',function(){
table.rows(':not(.' + $(this).val() + ')').remove().draw(true);
});
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://almsaeedstudio.com/themes/AdminLTE/plugins/datatables/dataTables.bootstrap.css">
<script src="https://almsaeedstudio.com/themes/AdminLTE/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://almsaeedstudio.com/themes/AdminLTE/plugins/datatables/dataTables.bootstrap.min.js"></script>
<table class="data-table table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Animal</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr class="all cat">
<td>Tiger Nixon</td>
<td>Cat</td>
<td>Edinburgh</td>
</tr>
<tr class="all cat">
<td>Garrett Winters</td>
<td>Cat</td>
<td>Tokyo</td>
</tr>
<tr class="all dog">
<td>Ashton Cox</td>
<td>Dog</td>
<td>San Francisco</td>
</tr>
<tr class="all horse">
<td>Lesley Manning</td>
<td>Horse</td>
<td>Washington</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签: jquery twitter-bootstrap datatables