Serverside; typing in 1 searchbox fires as many ajaxcalls as there are columns!
Serverside; typing in 1 searchbox fires as many ajaxcalls as there are columns!
Terradon
Posts: 16Questions: 5Answers: 2
I have added searchboxes in tfooter, but typing just one character in 1 searchbox, fires ajaxcalls for every column??
Somehow it does not make any differences between all the searchboxes. In my case it fires 5 ajaxcalls at once.
$("#mijnlogboek").DataTable({
"processing": true,
"serverSide": true,
"lengthMenu": [[10,50,200,500,-1], [10,50,200,500,"Alles"]],
"pagingType": "full_numbers",
language: {url: '//cdn.datatables.net/plug-ins/f2c75b7247b/i18n/Dutch.json'},
"ajax": "jq_datatables/mijnlogboek.php?playerID=1"
})
$('#mijnlogboek tfoot th').each( function () {
var title = $('#mijnlogboek thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Zoek '+title+'" />' );
} );
// DataTable
var table = $('#mijnlogboek').DataTable();
// Apply the search
table.columns().eq( 0 ).each( function ( colIdx ) {
$( 'input', table.column( colIdx ).footer() ).on( 'keyup change', function () {
table
.column( colIdx )
.search( this.value )
.draw();
} );
The table:
<table id="mijnlogboek" class="Xdisplay">
<thead>
<tr>
<th>datum tijd</th>
<th>actie</th>
<th>partij</th>
<th>tegenstander</th>
<th>beschrijving</th>
</tr>
</thead>
<tfoot>
<tr>
<th>datum tijd</th>
<th>actie</th>
<th>partij</th>
<th>tegenstander</th>
<th>beschrijving</th>
</tr>
</tfoot>
</table>
According to Firebug, it fires 5 ajaxcalls and for each columns it mentions the searchvalue, i typed in just 1 searchbox.
Apperently i am overseeing something but what?
Thanks in advance for any help!
This discussion has been closed.
Answers
I think the problem lays in:
table.column( colIdx )
coll dx seems to identify in which column i search? because if fires 5 ajaxcalls now and adds the searchterm to each column, instead to just 1 column.
But how?