2012-02-03 18 views
0

這種排序方向是一個方向,而不是其他方向。表規格有什麼問題嗎?如果有人可以發佈一個HTML樣本,這個HTML樣本具有在包含逗號的美元值的列上雙向工作的HTML樣本。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' 
}); 

不知道這裏需要table.tablesorter:

// 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(",","")); 
}