数据表-预填充搜索框 [英] Datatables - prepopulate search box

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

问题描述

我希望能够存储一个常见搜索词的列表,用户可以单击该列表,从而自动过滤数据表.

I want to be able to store a list of common search terms, which a user can click and thus automatically filter a datatable.

$('#table').on('preXhr.dt', function() {
    alert('test');//$search
})

http://datatables.net/reference/event/preXhr 上,我看到了此事件处理程序可用于在进行AJAX调用之前执行某些操作(这很完美-因为此时我可以截取脚本,因此请添加预先填充的搜索字词.

On http://datatables.net/reference/event/preXhr I saw this event handler could be used to do something before an AJAX call is made (which is perfect - as I could intercept the script at this point, add my prepopulated search term.

但是我发现第一次加载数据表时,不会触发此事件.

But I find that the first time the datatable loads, this event doesn't fire.

每当我进行排序等操作时,它都会在AJAX调用之前触发.

Any time I sort, etc it fires before the AJAX call.

但是我真的需要能够在加载初始数据集之前在 中访问数据表中的搜索框.

But I really need to be able to access the search box in Datatables before the initial dataset is loaded.

我该怎么做?

推荐答案

您可以在dataTables选项中指定初始搜索词:

You can specify the initial search term in the dataTables options:

$('#table').dataTables({
    search: {
       search: initialSearchTerm
    }
});

其中initialSearchTerm是保存初始搜索词的变量.

where initialSearchTerm is the variable that holds the initial search term.

请参见文档

这篇关于数据表-预填充搜索框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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