How to create a specific sorting function in jQuery Tablesorter?

前端 未结 1 1474
广开言路
广开言路 2021-01-06 06:52

I am using this great version of jQuery Tablesorter: http://mottie.github.com/tablesorter/docs/index.html

Everything is working well but now I have this problem: in

相关标签:
1条回答
  • 2021-01-06 07:19

    I figured it out by adding my own parser like it is shown in this question: Sorting Image and hyperlink columns in a table using JQuery Sorter plugin

    I will copy my script that works as I want it to work, hope it helps someone:

    $(document).ready(function() { 
    
        $.tablesorter.addParser({
                // set a unique id 
                id: 'positions',
                is: function(s) {
                        // return false so this parser is not auto detected 
                        return false;
                },
                format: function(s) {
                        // format your data for normalization 
                        return s.toLowerCase()
                                .replace("pg", "d")
                                .replace("sg", "h")
                                .replace("sf", "m")
                                .replace("pf", "r")
                                .replace("c", "v");
                },
                // set type, either numeric or text 
                type: 'text'
        });     
    
        $(".stats").tablesorter({
                sortInitialOrder: 'desc',
                sortRestart: true,
                headers: { 
                    0: { 
                            sortInitialOrder: 'asc'
                    }, 
                    1: { 
                            sortInitialOrder: 'asc'
                    },
                    2: { 
                            sorter: 'positions',
                            sortInitialOrder: 'asc'
                    }
                }
            }
        );
    
    });
    
    0 讨论(0)
提交回复
热议问题