【问题标题】:Trigger a sort on button click instead of full click with jQuery tablesorter?使用jQuery tablesorter触发按钮单击而不是完全单击的排序?
【发布时间】:2017-10-30 15:10:47
【问题描述】:

我正在使用这个 jQuery 表格排序器:https://mottie.github.io/tablesorter/docs/index.html。 我像这样初始化排序:

$('.sortable').tablesorter();

我的桌子是这样的:

<table class="sortable" id="list-users">
    <thead>
        <tr>
            <th>
                <div class="sorter"></div>
                ID
            </th>
            <th>
                <div class="sorter"></div>
                Name
            </th>
            <th>
                <div class="sorter"></div>
                Birth date
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
...

默认行为如下:当我点击一个标签时,表格会根据列进行排序。这很好。

但是我想在点击 div.sorter 时触发事件。 有人知道怎么做吗? 我试过这个:

$('table').find('th:eq(columnNumber)').trigger('sort');

但这当然不会禁用默认事件,这在您想触发事件时很有用。

谢谢!

【问题讨论】:

    标签: jquery tablesorter


    【解决方案1】:

    这个插件中实际上有一个可配置的选择器,可让您定义哪个元素触发排序。 Here's an example 来自项目文档。将其应用于您的标记,它可能看起来像:

    $(function() {
        // call the tablesorter plugin
        $(".sortable").tablesorter({
            selectorSort : 'div.sorter'
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 2019-05-31
      • 2011-04-03
      相关资源
      最近更新 更多