触发按钮单击排序而不是使用jQuery tablesorter进行完整单击?

格兰达尔313

我正在使用以下jQuery tablesorter: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>
...

默认行为如下:当我单击th标记时,表格将根据列进行排序。那很好。

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

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

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

谢谢!

该插件中实际上有一个可配置的选择器,可让您定义触发排序的元素。这是项目文档中的示例将其应用于您的标记,它可能类似于:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

反应:不是通过单击按钮进行排序 - 通过单击表中的标题“id”进行排序

jQuery使用按钮进行多次单击事件

在 jQuery Mobile 中单击按钮对列表视图进行排序

jQuery按钮单击事件未触发

jQuery触发按钮在表td中单击

使用jQuery tablesorter进行列排序

单击按钮对vuetify简单表进行排序

使用jQuery单击Gridview按钮

触发按钮单击

多次单击按钮触发

触发按钮单击Enter

jQuery 按钮单击不会触发表格中生成的按钮

使用JQuery按下按钮或锚点时触发多个单击事件

在 Internet Explorer 中的页面加载时使用 JavaScript 或 jQuery 以编程方式触发按钮单击事件

通过使用phonegap / cordova单击android native菜单按钮来触发jquery移动面板菜单

即使用户单击“中间按钮”或右键单击->在新选项卡中打开,如何触发jquery的“ click”事件

jQuery找到最接近的按钮并触发单击

jQuery-单击按钮时触发show(),hide()

jQuery无法触发另一个按钮的单击

jQuery移动按钮单击处理程序触发两次?

jQuery ajax按钮单击事件触发两次?

jQuery getJson成功函数在单击按钮时触发

单击按钮时不触发引导程序模态-jQuery

jQuery - 无需单击按钮即可触发函数

jQuery 在单击单选按钮时使用 id 而不是值显示 div

jQuery tablesorter无法对多个表进行排序

jQuery单击未触发

单击事件触发而无需单击按钮

Facebook Messenger Webhook通过单击按钮触发,但不是通过短信触发