Ich arbeite mit dem bootstrap dataTable und ich habe einen benutzerdefinierten Filter erstellt. Ich möchte alle Tiere nach Wert filtern. Zum Beispiel:Wie kann ich entfernte Zeilen in der Bootstrap DataTable wiederherstellen?
Wenn ich "Cat" auswählen, zeigen nur die Zeilen mit der Klasse "Katze".
Es funktioniert so weit, aber ich kann nicht herausfinden, wie die entfernten Zeilen wieder zurückgesetzt werden, wenn ich ein anderes Tier auswähle. Wenn meine Reihe einmal weg ist, kann ich sie nicht zurückbekommen.
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>
Das einzige Problem ist, gehe ich nicht zurück zu „All -
table.row().hide(deletedIndex)
eine gelöschte Zeile von Original-IndexAlle gelöschten Zeilen können durch
Demo wiederhergestellt werden wiederherstellen " – Jarla