使用数据表在输入标签内搜索
Search within input tag with Datatables
我最近发现了 DataTables (http://datatables.net/) 并一直在使用它的功能。
我 运行 在使用搜索功能时遇到了一些麻烦。我在 JSP 网络应用程序中使用数据表,我在其中使用表达式语言 (EL) 来提取和显示存储在会话中的信息。
这是我的代码示例:
<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>
搜索无法在输入标签的值属性内提取数据。我怎样才能让它看那里?
感谢任何指点,干杯!
您可以像这样为数据表创建自定义搜索功能:
$.fn.dataTableExt.ofnSearch['html-input'] = function(value) {
return $(value).val(); //will search in value attibute of element
};
然后将您的搜索功能附加到数据表:
var table = $("#example").DataTable({
columnDefs: [{ "type": "html-input", "targets": [0, 3] }]
});
这也是一个有效的fiddle
感谢@davidkonrad
我最近发现了 DataTables (http://datatables.net/) 并一直在使用它的功能。
我 运行 在使用搜索功能时遇到了一些麻烦。我在 JSP 网络应用程序中使用数据表,我在其中使用表达式语言 (EL) 来提取和显示存储在会话中的信息。
这是我的代码示例:
<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>
搜索无法在输入标签的值属性内提取数据。我怎样才能让它看那里?
感谢任何指点,干杯!
您可以像这样为数据表创建自定义搜索功能:
$.fn.dataTableExt.ofnSearch['html-input'] = function(value) {
return $(value).val(); //will search in value attibute of element
};
然后将您的搜索功能附加到数据表:
var table = $("#example").DataTable({
columnDefs: [{ "type": "html-input", "targets": [0, 3] }]
});
这也是一个有效的fiddle
感谢@davidkonrad