简体   繁体   English

单击元素以过滤javascript(数据表)中的列

[英]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. 我正在使用JavaScript DataTables显示数据,并想通过单击数据项以及标准菜单来修改过滤器。 For example, I have a table like this (obviously not including the javascript functions necessary to filter): 例如,我有一个这样的表(显然不包括过滤所需的javascript函数):

<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 . 使用ColumnFilterWidgetsColumnFilter

There are examples, snippets and docs in those pages. 这些页面中有示例,摘要和文档。 I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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