Datatables disable auto filter and added button

I use the datatables plugin, and I would like to turn off the automatic filter in the table and instead place the search button when they are fully entered in their text and are ready to continue the search.

JSfiddle:

$(document).ready(function() {
    $('#example').dataTable();
} );

http://jsfiddle.net/84KNZ/

the button (href) is the "Go" filter

any idea?

thank

+4
source share
2 answers

The first thing to do is to cancel the default keyup event from the search input:

$("div.dataTables_filter input").unbind();

Then we need to call data filtering from the moment of the link event:

 $('#filter').click(function(e){
        oTable.fnFilter($("div.dataTables_filter input").val());
    });

http://jsfiddle.net/84KNZ/3/

+12
source

, fnFilter , , , Enter , :

        $("div.dataTables_filter input").unbind();

        $("div.dataTables_filter input").on('keydown', function(e) {
            if (e.which == 13) {
                table.search( $("div.dataTables_filter input").val()).draw();
            }
        });
+2

Source: https://habr.com/ru/post/1544359/


All Articles