Datatables - 搜索框外的datatable [英] Datatables - Search Box outside datatable

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

问题描述

我正在使用数据表( datatables.net ),我希望我的搜索框不在表格之外(例如我的标题div)

I'm using DataTables (datatables.net) and I would like my search box to be outside of the table (for example in my header div).

这是可能吗?

推荐答案

你可以使用DataTables api过滤表。所以所有你需要的是你自己的输入字段与一个keyup事件触发过滤功能到DataTables。使用css或jquery可以隐藏/删除现有的搜索输入字段。或者可能DataTables有一个设置来删除/不包含它。

You can use the DataTables api to filter the table. So all you need is your own input field with a keyup event that triggers the filter function to DataTables. With css or jquery you can hide/remove the existing search input field. Or maybe DataTables has a setting to remove/not-include it.

查看Datatables API文档。

Checkout the Datatables API documentation on this.

示例:

HTML

<input type="text" id="myInputTextField">

JS

oTable = $('#myTable').DataTable();   //pay attention to capital D, which is mandatory to retrieve "api" datatables' object, as @Lionel said
$('#myInputTextField').keyup(function(){
      oTable.search($(this).val()).draw() ;
})

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

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