2012-11-15 34 views

回答

11

Tablesorter允許你爲這樣的事情定義"custom parsers"

// 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: { 
      6: {//zero-based column index 
       sorter:'thousands' 
      } 
     } 
    }); 
}); 

您可能需要調整格式函數。

也可以嘗試在此搜索頁面上,主題已經回答了討論很多次,像here

+0

如何id參數工作... ID:「成千上萬」,這是一個可定製的ID? –

+0

千位是解析器的唯一ID。另外,試着看看這個[例子](http://jsbin.com/equci5) – Jacta

1

有趣的問題,發現我所有的柱子下的ID考慮:文字,所以我修改喜歡的格式這個:

format: function(s) { 
    s=s.replace(new RegExp(/[^0-9A-Za-z ]/g),""); 
    return $.trim(s.toLowerCase()); 
} 

替換0-9,az,AZ以外的所有東西,當然還有空格字符。

花了我5小時的時間把我的頭靠在牆上(毫不誇張地說)來解決這個問題。

接受@ Jacta的答案反正,因爲它是起點,撞頭前:)

+0

如果你需要的話,你可能會問更多的細節,但很高興你能夠正常工作。 – Jacta