DataTables ajax callback on enter key
HTML
<script src="//cdn.datatables.net/1.10.6/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.6/css/jquery.dataTables.css">
<link rel="stylesheet" href="https://cdn.datatables.net/scroller/1.2.2/css/dataTables.scroller.min.css">
<script src="https://cdn.datatables.net/scroller/1.2.2/js/dataTables.scroller.min.js"></script>
<br><br>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Rating</th>
<th>Votes</th>
</tr>
</thead>
</table>
JavaScript
$('#example').on('xhr.dt', function ( e, settings, json, xhr ) {
var api = new $.fn.dataTable.Api(settings)
var info = api.page.info();
console.log('Data has been loaded', info);
});
$("#example").dataTable({
"scrollCollapse": true,
"serverSide": true,
"searching": true,
"ajax": function ( data, callback, settings ) {
setTimeout( function () {
var out = [];
for ( var i=data.start, ien=data.start+data.length ; i<ien ; i++ ) {
out.push( { id: i+'-1', name: i+'-2', rating: i+'-3', votes: i+'-4' } );
}
callback( {
"draw": data.draw,
"data": out,
"recordsTotal": 5000000,
"recordsFiltered": 5000000
});
}, 50 );
},
"ordering": true,
"deferRender": true,
"scroller": {
"loadingIndicator": true,
"trace": true,
},
//"dom": "rtiS",
"scrollCollapse": true,
"scrollX": true,
"scrollY": 400,
"bProcessing" : true,
"bDestroy" : true,
"bAutoWidth" : true,
/* "sScrollY" : "200",
"sScrollX" : "100%",*/
"scrollCollapse" : true,
//"sPaginationType" : "full_numbers",
//"iDisplayLength" : 25,
//"bLengthChange" : false,
fixedHeader: true,
"dom": 'Bfrtip',
"columns": [
{"data": "id"},
{"data": "name"},
{"data": 'rating'},
{"data": 'votes'}
]
});
$("#example_filter input")
.unbind()
.bind('keyup', function(e) {
if (e.keyCode == 13) {
console.log("after enter key"); //this statement is printing
$("#example").on('ajax', function ( data, callback, settings ) {
console.log("inside ajax request"); // this statement not printing
setTimeout( function () {
var out = [];
for ( var i=data.start, ien=data.start+data.length ;...