Search code examples
jquerytablesorter

jQuery TableSorter how to sort text/number from last to first char


i have table with one colum show state some day must to show from oldest to newest like (ex):

6417127(Mon:6,Tue:4,Wed:1,Thu:7,Fri:1,Sat:2,Sun:7)
6734976
9853385
1378454
6413366

how do i sort that colum each value from last char to first char (right to left). I tried to reverse text/number to sort, its ok but then it shows reversed text/number. if i add one more column with reversed values ​​seem funny. so how to sort that but not change orgin value? help me plz!


Solution

  • Try this:

    $.tablesorter.addParser({ 
            // set a unique id 
            id: 'weekdays', 
            is: function(s) { 
                // return false so this parser is not auto detected 
                return false; 
            }, 
            format: function(s) { 
                // format your data for normalization 
                return return s.split("").reverse().join("");  
            }, 
            // set type, either numeric or text 
            type: 'text' 
        }); 
    
        $(function() { 
            $("table").tablesorter({ 
                headers: { 
                    0: { 
                        sorter:'weekdays' 
                    } 
                } 
            }); 
        });