I would like to create external (next to DataTable table) input where user can enter zipCode.
When zipCode is between value of two columns (zip code from and zip code to) then show, otherwise hide the row.
my input and table are simple
<input id="zipCode_" class="input100 hidden-password" type="search" name="zipCode_">
<table id="table_zipCodes">
<thead>
<tr>
<th>Zone name</th>
<th>zip code from</th>
<th>zip code to</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>first</td>
<td>10-100</td>
<td>20-100</td>
<td>test</td>
</tr>
<tr>
<td>second</td>
<td>30-200</td>
<td>30-300</td>
<td>test2</td>
</tr>
[...]
</tbody>
and my script:
var table = $('#table_zipCodes').DataTable({
orderCellsTop: true,
fixedHeader : true,
'paging' : false
})
$('#zipCode_').on('keyup', function(event) {
var new_zipCode = $(this).val();
if (zipCode_value.length === 6) {
table.rows().every(function() { // <-- *i tried* table.rows(function(){
var this_row = this.data();
var col_from = this_row[1];
var col_to = this_row[2];
console.log(this_row); // <-- result below
console.log(this.child); // <-- result below
if (new_zipCode >= col_from && new_zipCode <= col_to) {
table.row(this).child().show(); // i<-- no reaction like below with hide()
}
else {
// I TRIED
//table.row(this).child().hide(); <- no reaction
//this.child.hide().draw(); <- no reaction
// this.hide() <- error "this.hide is not a function"
}
});
table.draw();
}
});
result from: console.log (this_row); as expected: one single row:
(4) ["first", "10-100", "20-100", "test"]
0: "first"
1: "10-100"
2: "20-100"
3: "test"
length: 4
__proto__: Array(0)
result from: console.log(this.child):
ƒ (){var d=b.apply(a,arguments);x.extend(d,
d,c.methodExt);return d}
The problem is, when i want to hide/show specific row it doesn't do anything. I read about external search with dataTable or search range but i want 'range' from one input and search two columns like so: if (new_zipCode >= col_from && new_zipCode <= col_to).
After two days I just give up... I can't solve it :(