简体   繁体   中英

Click on element to filter column in javascript (datatables)

I am using javascript DataTables to display data, and would like to modify filters by clicking on data items as well as the standard menus. For example, I have a table like this (obviously not including the javascript functions necessary to filter):

<table>
    <thead>
        <th>name</th>
        <th>number</th>
    </thead>
    <tbody>
        <tr>
            <td>Bob</td>
            <td>5</td>
        </tr>
        <tr>
            <td>Sue</td>
            <td>5</td>
        </tr>
        <tr>
            <td>Sue</td>
            <td>2</td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>1</td>
        </tr>
        <tr>
            <td>Frank</td>
            <td>5</td>
        </tr>
    </tbody>
</table>

If the viewer clicks on 'Bob', I want the filter to be updated to only display rows containing 'Bob'.

Use ColumnFilterWidgets or ColumnFilter .

There are examples, snippets and docs in those pages. I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM