2010-10-19 40 views
0

我有這樣一個HTML表格:的jQuery的tablesorter - 排序上括號內的漂浮

<table id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1"> 
    <thead> 
     <tr> 
      <th>Checkbox</th> 
      <th>Price delta</th> 
      <th>Price range</th> 
      <th>Price brackets</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td><input type="checkbox" id="chk1" name="chk1" value="Y" /></td> 
      <td><span class="price_up">Price up</span></td> 
      <td>(999.08) - (1025.67)</td> 
      <td>(1025.67)</td> 
     </tr> 
     <tr> 
      <td><input type="checkbox" id="chk2" name="chk2" value="Y" /></td> 
      <td><span class="price_down">Price down</span></td> 
      <td>(9.08) - (10.67)</td> 
      <td>(9.08)</td> 
     </tr> 
     <tr> 
      <td><input type="checkbox" id="chk3" name="chk3" value="Y" /></td> 
      <td><span class="price_up">Price up</span></td> 
      <td>(87.48) - (92.98)</td> 
      <td>(87.48)</td> 
     </tr> 
     <tr> 
      <td><input type="checkbox" id="chk4" name="chk4" value="Y" /></td> 
      <td><span class="price_up">Price up</span></td> 
      <td>(1.02) - (3.45)</td> 
      <td>(3.45)</td> 
     </tr> 
     <tr> 
      <td><input type="checkbox" id="chk5" name="chk5" value="Y" /></td> 
      <td><span class="price_down">Price down</span></td> 
      <td>(21.01) - (72.09)</td> 
      <td>(72.09)</td> 
     </tr> 
     <tr> 
      <td><input type="checkbox" id="chk6" name="chk6" value="Y" /></td> 
      <td><span class="price_up">Price up</span></td> 
      <td>(875) - (900)</td> 
      <td>(900)</td> 
     </tr> 
    </tbody> 
</table> 

,我試圖排序用下面的代碼第四列:

$("#tablesorter-demo").tablesorter({ 
     widgets: ['zebra'], 
    headers: { 
     3: { 
      sorter:'bracketedNumeric' 
     } 

    }   
    }); 

    // add parsing for numeric in brackets 
    $.tablesorter.addParser({ 
     // set a unique id 
     id: 'bracketedNumeric', 
     is: function(s) { 
      // return false so this parser is not auto detected 
      return false; 
     }, 
     format: function(s) { 
      // format your data for normalization 
      return s.Substring(s.IndexOf("(") +1, s.IndexOf(")")- s.IndexOf("(")- 1); 
     }, 
     type: 'floating' 
    }); 

但它不會出現正在工作。

回答

0

設法用下面的解析器排序是:

// bracketed float parser 
    $.tablesorter.addParser({ 
     // set a unique id 
     id: 'floatBracket', 
     is: function(s) { 
      // return false so this parser is not auto detected 
      return false; 
     }, 
     format: function(s,table,cell) { 
      // format your data for normalization 
      var cellTxt = s.replace("(", "").replace(")", ""); 
      return cellTxt; 
     }, 
     // set type, either numeric or text 
     type: 'floating' 
    });