使用数据表在输入标签中搜索 [英] Search within input tag with Datatables
问题描述
我最近发现了DataTables( http://datatables.net/),并且一直在使用它的功能.
I recently discovered DataTables (http://datatables.net/) and have been playing around with its features.
我在使用搜索功能时遇到了麻烦.我在JSP Web应用程序中使用DataTables,在这里我使用表达式语言(EL)提取并显示会话中存储的信息.
I'm running into a bit of trouble with the search feature. I'm using DataTables in a JSP webapp, where I use expression language (EL) to pull and display information stored in the session.
以下是我的代码示例:
<table id="list" class="table table-hover results">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<c:forEach var="elt" items="${listCandidates}">
<tr>
<td>
<form action="ViewFullCandidateProfileServlet">
<a href="#">
<input type="hidden" name="candidateID" value="${elt.candidateID }">
<input type="submit" name="View Profile" value="${elt.firstName} ${elt.lastName}">
</a>
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
搜索无法在输入标签的value属性内拾取数据.我该如何指示它在那里?
The search fails to pick up data within the value attribute in the input tags. How can I direct it to look there?
感谢所有指针,干杯!
推荐答案
您可以像这样为数据表创建自定义搜索功能:
You can create your custom search functionality for your datatables like this:
$.fn.dataTableExt.ofnSearch['html-input'] = function(value) {
return $(value).val(); //will search in value attibute of element
};
,然后将搜索功能附加到数据表:
and then attach your search functionality to datatables:
var table = $("#example").DataTable({
columnDefs: [{ "type": "html-input", "targets": [0, 3] }]
});
这里也是有效的小提琴
感谢@davidkonrad
Thanks to @davidkonrad
这篇关于使用数据表在输入标签中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!