开发者

jQuery filtering & sorting of tables - how to look "inside" html tags

I am making use of a tablesorter library. My issue is that every item in a cell inside of my table is a link, and the library starts sorting things incorrectly because it's looking at the HTML inside the cell, instead of the text. In other words, in the following cell contents;

<a href="ledger.php?var=345345">$100.64</a> it sorts on:

<a href="ledger.php?var=345345"> instead of $100.64

I know there are ways to look at the text inside of cells. I started with the simple method that they have listed on the website, text extraction method. However, I can't for the life of me get this to function properly.

Using my JS code, can anyone tell me how to apply this text extraction properly? This is what I have now (be开发者_开发问答low).

The current results of this code, when the "text extraction" line is NOT commented out, is that the plugin fails to load, and all jQuery on the page fails with it. The console error in web developer plugin is:

Error: node.childNodes[0].childNodes[0] is undefined Source File:

$(document).ready( function () {
            // TableSorter
                $("#dt-results") 
                .tablesorter({
                                widgets: ['zebra'], 
                                sortList: [[0,1]],

                                // define a custom text extraction function 
                                textExtraction: function(node) { 
                                    // extract data from markup and return it  
                                    return node.childNodes[0].childNodes[0].innerHTML; 
                                } 
                })
                .tablesorterPager({container: $("#pager")})
                .tablesorterFilter({filterContainer: $("#filter-box"),
                              filterClearContainer: $("#filter-clear-button"),
                              filterCaseSensitive: false,
                              filterWaitTime: 100});
        });

Thanks


Since you are using jQuery, why don't you use text()? See http://api.jquery.com/text/

textExtraction: function(node) {
    return $(node).text();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜