Search within input tag with Datatables

别说谁变了你拦得住时间么 提交于 2019-12-13 02:16:06

问题


I recently discovered DataTables (http://datatables.net/) and have been playing around with its features.

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.

Here is a sample of my code:

<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>

The search fails to pick up data within the value attribute in the input tags. How can I direct it to look there?

Appreciate any pointers, Cheers!


回答1:


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] }] 
});

Here is also a working fiddle

Thanks to @davidkonrad



来源:https://stackoverflow.com/questions/35001142/search-within-input-tag-with-datatables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!