Jquery Tablesorter,按链接url而不是链接内容排序

编程入门 行业动态 更新时间:2024-10-10 06:17:46
本文介绍了Jquery Tablesorter,按链接url而不是链接内容排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在使用第一列(共 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">zzz</a></td><td>11</td><td>22</td><td>33</td></tr>
<tr><td><a href="http://cba">aaa</a></td><td>11</td><td>22</td><td>33</td></tr>
<tr><td><a href="http://bbb">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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 11:19:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   而不是   内容   Jquery   Tablesorter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!