首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery - tablesort只在一个方向上有效

jquery - tablesort只在一个方向上有效
EN

Stack Overflow用户
提问于 2012-02-03 10:11:35
回答 1查看 690关注 0票数 0

这是在一个方向上排序,但不是在另一个方向上。桌子的规格有什么问题吗?如果有人能发布一个HTML示例,在包含逗号的美元值列上进行双向排序,那就太好了。

代码语言:javascript
复制
// 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):

代码语言:javascript
复制
// 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:

代码语言:javascript
复制
// specify column  
$(function() {  
    $("table.tablesorter").tablesorter({  
        headers: {  
            // column to be handled specially
            7: {  
                sorter:'money'  
            }  
        }
    });
});                 
</script>

下面是表格的顶部:

代码语言:javascript
复制
<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>  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-07 05:21:51

由于您使用的是数字,因此需要将字符串解析为实数。在解析器中更改这一行:

代码语言:javascript
复制
format: function(s) {
  return parseFloat( s.toLowerCase().replace("\$","").replace(",","") );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9122839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档