Based on this discussion, added code below into my JS code to enable filtration to be triggered by pressing the enter key instead of keyup or delay.
jQuery.fn.dataTableExt.oApi.fnSetFilteringPressEnter = function (oSettings) {
var _that = this;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var $this = this;
var anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl.unbind('keyup').bind('keypress', function (e) {
if (e.which == 13) {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}
});
return this;
});
return this;
}
/* Example call */
$(document).ready(function() {
$('.dataTable').dataTable().fnSetFilteringPressEnter();
} );
Now what I want to do is, when user removes keyword from search bar, I want to redraw table. Currently it doesn’t redraw without pressing enter button. How can I achieve this result?
I think its safe to do on the keyup event of keyboard, unlike only triggering on the
enterkey press.Also, note I have used
on()andoff()for delegation instead ofbindandunbindwhich are deprecated as of jQuery 1.7Or, you can create a completely different handler for the specific case, where all the keywords are deleted on the text box.