sort table by price column

前端 未结 5 898
野趣味
野趣味 2021-01-23 20:44

It\'s the billing list:

Service   Price
---------------
S1        13 CHF
S2        Free
S3        Free
S4        40 CHF

I want to sort it by pr

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 21:23

    You can write your own parser. See the documentation at: http://tablesorter.com/docs/example-parsers.html

    Working example:

    $.tablesorter.addParser({ 
        id: 'price', 
        is: function(s) { 
            return false; 
        }, 
        format: function(s) { 
            return s.replace(/Free/,0).replace(/ CHF/,""); 
        }, 
        type: 'numeric' 
    }); 
    
    $(function() { 
        $("table").tablesorter({ 
            headers: { 
                1: { 
                    sorter:'price' 
                } 
            } 
        }); 
    });
    

    http://jsfiddle.net/8BCHR/

提交回复
热议问题