2012-02-03 13 views
0

これは一方向に並べ替えますが、もう一方には並べません。テーブルの仕様に問題がありますか?誰かがコンマを含むドル値を持つ列の両方向で作業しているソートを持つHTMLサンプルを投稿することができれば嬉しいことです。プレフィックスはこちら(table.tablesorter)必要な場合はjquery-tablesortは一方向のみで動作します

// create sorter 
<script type="text/javascript" id="js"> 
    $(document).ready(function() { 
     // call the tablesorter plugin 
     $("table.tablesorter").tablesorter({ 
      // enable debug mode 
      debug: false 
     }); 
    }); 
</script> 

わからない:table.tablesorterはここで必要とされている

// add parser through the tablesorter addParser method 
<script type="text/javascript" id="js"> 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'money', 
    is: function(s) { 
     // return false so this parser is not auto detected 
     return false; 
    }, 
    format: function(s) { 
     return s.toLowerCase().replace("\$","").replace(",",""); 
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

わからない場合:

// specify column 
$(function() { 
    $("table.tablesorter").tablesorter({ 
     headers: { 
      // column to be handled specially 
      7: { 
       sorter:'money' 
      } 
     } 
    }); 
});     
</script> 

次はトップでありますテーブルの:

<table cellspacing="1" class="tablesorter"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Major</th> 
      <th>Gender</th> 
      <th>English</th> 
      <th>Japanese</th> 
      <th>Calculus</th> 
      <th>Overall grades</th> 
      <th>Money</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Student01</td> 
      <td>Languages</td> 
      <td>male</td> 
      <td>80</td> 
      <td>70</td> 
      <td>75</td> 
      <td>bad</td> 
      <td>$1.00</td> 
     </tr> 

答えて

0

数字で作業しているので、文字列を実数に解析する必要があります。パーサーで次の行を変更してください。

format: function(s) { 
    return parseFloat(s.toLowerCase().replace("\$","").replace(",","")); 
} 
関連する問題