jQuery Table排序器:停止排序 [英] jQuery Table sorter: stop sorting

查看:76
本文介绍了jQuery Table排序器:停止排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户单击表标题th内的div,是否可以停止表排序?

Is it possible to stop table sorting if user clicks on div inside of table header th?

就我而言,div具有执行功能onClick="resize(e)"的功能:

In my case div has function onClick="resize(e)" on which I do:

function resize(e) {
        if (!e) var e = window.event;
        e.stopPropagation();
        ....

但这是行不通的.

表在e.stopPropagation()return false

推荐答案

我为您制作了两个演示.第一个将表标头的内容包裹在一个范围中,第二个使用未记录的onRenderHeader函数将span添加到标头内.无论哪种方式,只有span的内容都是可单击的(文本),而在内容的外部单击将对列进行排序.如果使用div,则仅标题填充符可用于初始化列排序.

I made two demos for you. The first one has the content of the table header wrapped in a span and the second one uses the undocumented onRenderHeader function to add the span inside the header. Either way, only the contents of the span are clickable (the text) while clicking outside of the content will sort the column. If you use a div only the header padding is available to initialize a column sort.

演示1 -标头内容包含在标记中

Demo 1 - header contents wrapped in the markup

$('table')
    .tablesorter()
    .find('.inner-header')
    .click(function(){
        console.log('header text clicked');
        return false;
    });

演示2 -使用onRenderHeader选项包装的标头内容

Demo 2 - header content wrapped using the onRenderHeader option

$('table').tablesorter({

    // customize header HTML
    onRenderHeader: function(index) {
        $(this)
            .wrapInner('<span class="inner-header"/>')
            .find('.inner-header')
            .click(function(){
                console.log('header text clicked');
                return false;
            });
    }

});​

如果您需要有关使用onRenderHeader选项的更多信息,请查看我的博客文章有关文档中缺少的内容.

If you need more information on using the onRenderHeader option, check out my blog post on what's missing in the documents.

这篇关于jQuery Table排序器:停止排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆