Datatables - Search; but do not instantly filter the data table

做~自己de王妃 提交于 2019-12-12 03:09:47

问题


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:


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)



来源:https://stackoverflow.com/questions/39464462/datatables-search-but-do-not-instantly-filter-the-data-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!