Datatable filter doesn't work
Datatable filter doesn't work
don_greg
Posts: 1Questions: 1Answers: 0
Why filtering by name column doesn't work? Could somebody help with that?
There is an input with id="name"
which should filter values by name column of the table. But it doesn't work. What is wrong?
HTML:
<div>
<input type="text" id="name" name="name" placeholder="Name">
</div>
<table id="shTable" class="table table-striped table-bordered dataTable no-footer dtr-inline" role="grid" aria-describedby="shTable_info">
<thead class="">
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>
JavaScript:
<script>
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var max = parseInt( $('#max').val(), 10 );
var name = $('#name').val();
var age = parseFloat( data[3] ) || 0; // use data for the age column
var name_table = (data[0]);
if ( isNaN( max ) || ( age <= max ) || ( isNaN( max ) ) || ( age <= max ) || name_table.indexOf(name) > -1 )
{
return true;
}
return false;
}
);
$(document).ready(function() {
var table = $('#shTable').DataTable();
// Event listener to the two range filtering inputs to redraw on input
$('#max, #name').keyup( function() {
table.draw();
} );
} );
</script>
This discussion has been closed.