I am using jquery datatable to show data in my table.
$(document).ready(function () {
var otable;
otable = $(".table").dataTable();
function filterme() {
//build a regex filter string with an or(|) condition
var types = $('input:checkbox[name="Hotel"]:checked').map(function () {
return '^' + this.value + '$';
}).get().join('|');
//filter in column 0, with an regex, no smart filtering, no inputbox,not case sensitive
otable.fnFilter(types, 1, true, false, false, false);
}
$("#btn1").click(filterme);
$("#btn2").click(filterme);
});
As u can see , there is a simple function filterme which is firing on corresponding checkboxes click event.
This is my whole Table :
<table class="table">
<thead>
<tr>
<th>Image</th>
<th>Hotel</th>
</tr>
</thead>
@foreach (var item in Model.HotelSearchResult.HotelResults)
{
<tbody>
<tr>
<td>
<img src=@item.HotelPicture />
</td>
<td>
@item.HotelName
</td>
</tr>
</tbody>
}
</table>
and these are the checkboxes :
<input id ="btn1" type="checkbox" name="Hotel" value="Majestic Place">Majestic place
<input id="btn2" type="checkbox" name="Hotel" value="Bonlon Inn">Bonlon Inn
But problem is, whenever checkbox is checked, filterme function get called but in datatable only first row dissappears and at that palce its shown "No matching records found" and all remaining rows remains there. whatever checkbox i check only one top row get dissappeared and all rows with data remains there.
I am following this plunker.http://plnkr.co/edit/b8cLVaVlbNKOQhDwI2mw?p=preview got reference through one of so question. Please help me out.
Aucun commentaire:
Enregistrer un commentaire