It is not a bug, it is the expected behaviour. You are using a paginated table, and then
$('#example td').click( function () {
alert('x');
});
is executed, you actually only attach the click handler to visible <td>
's, i.e <td>
's on page #1. You must use a delegated event handler in order to target all <td>
's at any time, also those injected to the DOM dynamically :
$('#example').on('click', 'td', function () {
alert('x');
});
your demo edited -> http://live.datatables.net/fizajopa/3/edit
Update, I see the problem. Simply call blur()
in the filter input handler :
$("#example thead th input[type=text]").on( 'keyup change', function () {
table
.column( $(this).parent().index()+':visible' )
.search( this.value )
.draw();
$(this).blur() //<----
});
But that will remove focus from the <input>
each time anything is typed or changed, also if the user wants to type more. To avoid that you can use an approach like this jQuery .keyup() delay :
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
// Apply the filter
$("#example thead th input[type=text]").on( 'keyup change', function () {
var that = this;
delay(function(){
table
.column( $(that).parent().index()+':visible' )
.search( that.value )
.draw();
$(that).blur()
}, 500);
});
$('body').on('click', 'td', function () {
alert('x');
});
forked demo -> http://live.datatables.net/xoyutune/1/edit
Dont know if 500ms is suitable, you can experiment with that.