【问题标题】:Exclude child elements from a table cell using tablesorter filter widget使用 tablesorter 过滤器小部件从表格单元格中排除子元素
【发布时间】:2013-05-08 07:59:14
【问题描述】:

是否可以使用 tablesorter 过滤器小部件从表格单元格中排除子元素?

即如果我在过滤框中输入Mia,我只想显示第二行。但是过滤器小部件的默认行为是搜索表格单元格的所有内容,因此第 1 行也显示为 Mia 也在第 1 行的<div class="information"> 中。

<table>
    <thead>
        <tr>
            <td>Name</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                John
                <div class="information">
                    He is 25 years old and has a sister called Mia
                </div>
            </td>
        </tr>
        <tr>
            <td>Mia</td>
        </tr>
    </tbody>
</table>

我正在使用$('table').tablesorter({ widgets: ['filter'] }); 来启动表格排序器。

如果不可能,我必须将每个单元格的附加信息放在其他地方。

【问题讨论】:

    标签: jquery filter tablesorter


    【解决方案1】:

    您可以结合使用 textExtraction 函数和 filter_useParsedData 选项 (demo):

    $('table').tablesorter({
        theme: 'blue',
        textExtraction: {
            0: function (node) {
                return $(node).contents().filter(function () {
                    return this.nodeType === 3;
                }).text();
            }
        },
        widgets: ['zebra', 'filter'],
        widgetOptions: {
            filter_useParsedData: true
        }
    });
    

    【讨论】:

    • 谢谢,效果很好! =) 想解释一下 textExtraction 函数中发生了什么?
    • 好的,当我稍微研究一下时,它实际上非常简单。再次感谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 2018-10-08
    相关资源
    最近更新 更多