1

I had problems handling currencies, then I used this code

<script type='text/javascript'> 
$(document).ready(function () {
    $(&quot;#3dprojector&quot;).tablesorter(); 
    } 
    ); 

    // add parser through the tablesorter addParser method 
    $.tablesorter.addParser({ 
    // set a unique id 
    id: 'thousands',
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) {
        // format your data for normalization 
        return s.replace('$','').replace(/,/g,'');
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
    }); 

    $(function() {
    $("table").tablesorter({
        headers: {
            1: {//zero-based column index
                sorter:'thousands'
            }
        }
    });
    });
</script>

the problem is, it only sorts only one way. I'm not sure if I have used parser the right way. This script is before finishing /head tag on my website. Thanks for help :-)

4

1 回答 1

0

您实例化了 2 次 tablesorter,一次在 3dproject 的表上一次(由于 3 而失败的可能性很高)

<script type='text/javascript'> 

jQuery(function($,undefined) {


// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
// set a unique id 
id: 'thousands',
is: function(s) { 
    // return false so this parser is not auto detected 
    return false; 
}, 
format: function(s) {
    // format your data for normalization 
    return s.replace('$','').replace(/,/g,'');
}, 
// set type, either numeric or text 
type: 'numeric' 
}); 


$("table").tablesorter({
    headers: {
        1: {//zero-based column index
            sorter:'thousands'
        }
    }
});
});
</script>

这对你有什么好处?粘贴控制台错误以防万一

于 2013-11-10T17:03:09.330 回答