Jquery Tablesorter, sorting by link url rather than link content

柔情痞子 提交于 2019-12-04 10:14:43

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>

I fixed it by inserting a span with style display:none before the link. In the span put the link text.

e.g.

<td><span style="display:none"><%= Html.Encode(item.Name) %></span>
                <a href='<%= Url.Action("Edit", new {id=item.Id}) %>'>
                    <%= Html.Encode(item.Name) %></a>
            </td>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!