[英]how to add filter to datatable
I have made a dataTable and populated it with many fields, but I would like to add my own search/filter function to it. 我已经制作了一个dataTable并在其中填充了许多字段,但是我想向其中添加自己的搜索/过滤器功能。
I have a textbox that I am using as the search/filter: 我有一个用作搜索/过滤器的文本框:
<div class="filterTable">
<form>
<input id="tableSearch" type="text" placeholder="filter">
</form>
</div>
And this is the JavaScript function that I have added for it: 这是我为其添加的JavaScript函数:
$("tableSearch").keyup(function () {
var string = document.getElementById("tableSearch").value;
oTable.fnFilter(string);
});
oTable is the initialized dataTable. oTable是已初始化的dataTable。
The problem I am having is that the JavaScript function is never hit. 我遇到的问题是JavaScript函数从未被使用过。 Any Ideas? 有任何想法吗?
You should use the # tag for reffering the ID of an element. 您应该使用#标记来表示元素的ID。
Try with the below mentioned code. 尝试使用下面提到的代码。
$("#tableSearch").keyup(function () {
var string = $(this).val();
oTable.fnFilter(string);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.