Datatables - Search; but do not instantly filter t

2019-09-11 13:10发布

I have been starting to use datatables.net jQuery library and its searching method. However, I currently I have the following problem:

I would like to use the search functionality but I do not want to have the automatically filtering available. In other words, when I search for a term, I would like to keep all the data in the table. By default, the search functions as a filter (instant-search). This means on key-up the data table shrinks when the term has not been matched and only the rows are displayed that contain the term. This is not what I need. Has anybody experienced this problem before and has a solution for it?

Unfortunately, I haven't found anything on the datatables.net website.

Thanks!

1条回答
ら.Afraid
2楼-- · 2019-09-11 13:40

You haven't said how you want the search to perform, so I'll assume it's on the Return key press.

First you need to unbind the default 'keyup' event from the search input:

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

Then bind a new event which checks that the return key has been pressed, then perform the search:

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

Where oTable is your datatable object

You haven't said which version of Datatables you're using, this is v1.9 syntax. To change it to v1.10 you need to use oTable.search(this.value)

查看更多
登录 后发表回答