【问题标题】:Tablesorter Custom Parser not workingTablesorter 自定义解析器不工作
【发布时间】:2014-04-19 01:51:17
【问题描述】:

我正在尝试创建自己的 tablesorter 解析器,但它不起作用。我用 PHP 和我的 MySQL 数据库生成表。这是问题所在:在我的列中,0 类似于 5.98 (50%) 和 10.67 (100%) (http://i.epvpimg.com/NsTlb.png)。我尝试对括号进行正则表达式以对其进行正确排序(正则表达式有效)但 Tablesorter 只是将 100% 的东西放在底部:/ 您可以在此处查看自己激活调试的结果:http://maxiboether.ma.funpic.de/x264/index2.php

这是我的代码:

<head>
<meta charset="utf-8">
    <title>x264 Benchmark</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<script src="http://tablesorter.com/__jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.metadata.js"></script>
<script type="text/javascript" src="js/jquery.hoverIntent.js"></script>
<script type="text/javascript" src="js/mbMenu.js"></script>
<script src="js/textext.core.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">

<script type="text/javascript">
 $.tablesorter.addParser({ 
        // set a unique id 
        id: 'customFPS', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s) { 
            // format your data for normalization 
             return $.tablesorter.formatFloat(s.replace(/ *\([^)]*\) */g, ""));

        }, 
        // set type, either numeric or text 
        type: 'numeric' 
    }); 
$(document).ready(function() 
    { 
        $("#keywords").tablesorter({ 
        // enable debug mode 
        debug: true 
        }); 
        $("#keywords").tablesorter({
            headers: {
                0: {sorter:'customFPS'}
            }
        }); 
        $("#keywords").tablesorter({
            sortList: [[0,1]]
        }); 


    } 
); 

</script>

我在这里做错了什么?

此致,

梅斯特斯

【问题讨论】:

    标签: jquery regex tablesorter


    【解决方案1】:

    我通过让 Tablesorter 决定这是否是 FPS 列来解决它!

    我现在的代码是:

     $.tablesorter.addParser({ 
            // set a unique id 
            id: 'customFPS', 
            is: function(s) { 
                // return false so this parser is not auto detected 
                return s.match(new RegExp(/ *\([^)]*\) */g));
            }, 
            format: function(s) { 
                // format your data for normalization 
                 return $.tablesorter.formatFloat(parseFloat(s.replace(/ *\([^)]*\) */g, "")));
    
            }, 
            // set type, either numeric or text 
            type: 'numeric' 
        }); 
    

    【讨论】:

    • 很高兴您找到了答案,但实际问题是 tablesorter 被初始化了 3 次。看this demo,它显示了如何添加多个选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 2023-04-05
    • 1970-01-01
    • 2016-01-12
    相关资源
    最近更新 更多