2012-02-25 29 views
1

このJS fiddle:http://jsfiddle.net/DE5Bpをチェックしてください。タリフの列を最初の桁、Tablesorterプラグインは、数字とテキストが混在していても正しくソートしていません

どうすればこの問題を解決できますか?

<span class="hide">でプラグインを騙そうとしたのがわかりましたが、これで問題は解決しませんでした。

UPDATE:それは仕事を得るために数値:http://jsfiddle.net/6jAyF/このバージョンでは、私はあなたがタイプとaddParserを使用したいと考えていsorter:"integer"

答えて

1

を強制します。数値ソーターを使用するhttp://tablesorter.com/docs/example-parsers.htmlのコードスニペットを示します。

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'grades', 
    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(/good/,2).replace(/medium/,1).replace(/bad/,0); 
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

$(function() { 
    $("table").tablesorter({ 
     headers: { 
      6: { 
       sorter:'grades' 
      } 
     } 
    }); 
}); 
+0

私が探していたものです。これはデフォルトでプラグインに組み込まれていません。私の問題を完全に解決するには、最初の番号を取得する必要があります。http://stackoverflow.com/questions/609574/get-the-first-ints-in-a-string-with-javascript –

+1

@JohnMagnoliaあなたの値を適切にソートするためにカスタムパーサの 'parseInt()'を使います。 - [demo](http://jsfiddle.net/Mottie/6jAyF/2/)。 – Mottie

+0

@fudgey - はいこれはたくさんのクリーナーです、ありがとうございます:-) –

関連する問題