Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables global search on keypress of enter key instead of any key keypress

I am using Datatables plugin of jQuery. I am using server side processing functionality for my ASP.Net project.

Its get frustrating when each time I try to type something in global search, with each letter I type it calls the server side method and brings result for me.

It gets more frustrating when the data to be filter is large.

Is there any option or way to call search method on keypress of enter key and not on any key press?

like image 605
Prasad Jadhav Avatar asked Sep 07 '25 16:09

Prasad Jadhav


1 Answers

What to do is to just unbind the keypress event handler that DataTables puts on the input box, and then add your own which will call fnFilter when the return key (keyCode 13) is detected.

$("div.dataTables_filter input").keyup( function (e) {
    if (e.keyCode == 13) {
        oTable.fnFilter( this.value );
    }
} );

Else

$(document).ready(function() {
   var oTable = $('#test').dataTable( {
                    "bPaginate": true,
                "bLengthChange": true,
                "bFilter": true,
                "bSort": true,
                "bInfo": true,
                    "bAutoWidth": true } );
   $('#test_filter input').unbind();
   $('#test_filter input').bind('keyup', function(e) {
       if(e.keyCode == 13) {
        oTable.fnFilter(this.value);   
    }
   });     
} );
like image 159
Techie Avatar answered Sep 10 '25 05:09

Techie