开发者

Tablesorter : how to ignore text in cells

When using tablesorter I cannot sort out properly when I add something to sa开发者_开发知识库y a number in a table cell. eg. 30 MB, 50 MB etc.

Is there anyway of telling the sorting to ignore text in a cell ie. the MB in this example?

Also, about in-line styling and tags: How can I sort out the following properly?

<td><span>upto</span> 50 <br /> MB</td>

Taking into account the 'upto' and 'MB' text and the <br /> tag.


I found the "problem" was solved in a forked/updated version of the tablesorter code hosted on the jQuery site. The forked version is here: http://mottie.github.com/tablesorter/docs/index.html


Try passing the textExtraction option to the tableSorter method.

Something in the lines of:

var extractData = function(node)  {      
    return $(node).text().replace(/[^0-9.]/g, ''); 
} 

$(document).ready(function()     {         
    $("#yourTable").tableSorter( {
        textExtraction: extractData
        } ); 
} ); 

Link for DOC: http://tablesorter.com/docs/

Check example @:http://tablesorter.com/docs/example-option-text-extraction.html


Found another way of doing it: change the codes as follows:

<td>upto<br /><span>50</span>MB</td>

the apply the following text extraction:

textExtraction: {
        3: function(node) {
               return $(node).find("span:last").html();
        }
    }


As reported in other answers I'm using tablesorter textExtraction feature

I found useful this sort attribute solution when dealing with table that have both complex and simple column markups:

$(".tablesorter").tablesorter({
    textExtraction: function(node) { 
        // look for a 'sort' attribute in <td> element
        var sort = node.getAttribute('sort');
        if(sort){
            //use it for sorting if found
            return sort;
        }else{
            //default sorting behaviour if not found
            return node.innerHTML;
        }   
    }       
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜