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

4 tablesorter

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

<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>
Run Code Online (Sandbox Code Playgroud)

它会订购

zzz
ccc
aaa
Run Code Online (Sandbox Code Playgroud)

而不是字母.这是故意的吗?是否有任何人可以建议的解决方案?

谢谢

Kir*_*ill 8

我有同样的问题.在文档中找到解决方案.需要为链接添加解析器,以便<a>在排序时从列中文本的开头删除标记.

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

 <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>
Run Code Online (Sandbox Code Playgroud)