Jquery Tablesorter,按链接url而不是链接内容排序 [英] Jquery Tablesorter, sorting by link url rather than link content

查看:27
本文介绍了Jquery Tablesorter,按链接url而不是链接内容排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用第一列(共 4 列)中的链接的表格上使用 Tablesorter.问题是,在 FF 和 Chrome 中,当通过 url 而不是链接的内容点击时,它对第一列进行排序.例如

I am using Tablesorter on a table which uses links in the first column (of 4). The problem is that in FF and Chrome it orders the first column when clicked by url not the content of the link. For example

<tr><td><a href="http://abc.com">zzz</a></td><td>11</td><td>22</td><td>33</td></tr>
<tr><td><a href="http://cba.com">aaa</a></td><td>11</td><td>22</td><td>33</td></tr>
<tr><td><a href="http://bbb.com">ccc</a></td><td>11</td><td>22</td><td>33</td></tr>

它会订购

zzz
ccc
aaa

而不是按字母顺序排列.这就是这种情况吗?有人可以建议修复吗?

instead of alphabetical. Is this meant to be the case? Is there a fix anyone can suggest?

谢谢

推荐答案

我遇到了同样的问题.在 文档 中找到解决方案.需要为链接添加一个解析器,在排序时从列中文本的开头删除 标签.

I have got the same problem. Found solution in the Documentation. Need to add a parser for the links which removes <a> tags from the beginning of the text in a column while sorting.

这是应该可以解决您的问题的代码:

Here is code which should solve your problem:

 <script type="text/javascript">
    // add parser through the tablesorter addParser method 
    $.tablesorter.addParser({
        // set a unique id 
        id: 'links',
        is: function(s)
        {
            // return false so this parser is not auto detected 
            return false;
        },
        format: function(s)
        {
            // format your data for normalization 
            return s.replace(new RegExp(/<.*?>/),"");
        },
        // set type, either numeric or text
        type: 'text'
    }); 


    // Apply "links" parser to the appropriate column
    $(document).ready(function()
    {
        $("#MyTable").tablesorter({
            headers: {
                0: {
                    sorter: 'links'
                }
            }
    });
</script>

这篇关于Jquery Tablesorter,按链接url而不是链接内容排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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