数据表-搜索;但不要立即过滤数据表 [英] Datatables - Search; but do not instantly filter the data table

查看:131
本文介绍了数据表-搜索;但不要立即过滤数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用datatables.net jQuery库及其搜索方法.但是,我目前遇到以下问题:

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?

不幸的是,我没有在datatables.net网站上找到任何东西.

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

谢谢!

推荐答案

您还没有说出搜索的执行方式,所以我假设它是在Return键上按下的.

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

首先,您需要从搜索输入中取消绑定默认的"keyup"事件:

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);
        }
    });

oTable是您的datatable对象

您尚未说出正在使用哪个版本的Datatables,这是v1.9语法.要将其更改为v1.10,您需要使用oTable.search(this.value)

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)

这篇关于数据表-搜索;但不要立即过滤数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆