最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - datatables disable auto filter and added a button - Stack Overflow

programmeradmin0浏览0评论

I'm using datatables plugin and i would like to disable the auto filter on the table and instead put a search button when they've fully entered their text and are ready to search further.

JSfiddle :

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

/

the button (href) is "Go filter"

any idea ?

thanks

I'm using datatables plugin and i would like to disable the auto filter on the table and instead put a search button when they've fully entered their text and are ready to search further.

JSfiddle :

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

http://jsfiddle.net/84KNZ/

the button (href) is "Go filter"

any idea ?

thanks

Share Improve this question edited Jun 13, 2014 at 7:55 user3734830 asked Jun 12, 2014 at 16:01 user3734830user3734830 631 silver badge4 bronze badges 1
  • Please add some meaningful code and a problem description here. For more help, see stackoverflow.com/help/mcve – Steve Commented Jun 12, 2014 at 18:10
Add a comment  | 

2 Answers 2

Reset to default 14

First thing to do is unbind the default keyup event from the search input:

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

Then we need to call the datatable filtering from the link click event:

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

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

If you are using server side processing, fnFilter do not work, you have to use search, also, it will be better to perform the search by pressing Enter in the search textbox, this can be achieved as follows:

        $("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();
            }
        });
发布评论

评论列表(0)

  1. 暂无评论