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

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

问题描述

我正在使用 DataTables (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 事件,可以触发数据表的过滤功能.使用 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() ;
})

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

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