Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 表排序器日期dd.mm.yyyy_Jquery_Date_Tablesorter - Fatal编程技术网

Jquery 表排序器日期dd.mm.yyyy

Jquery 表排序器日期dd.mm.yyyy,jquery,date,tablesorter,Jquery,Date,Tablesorter,我有以下表格: <table class='tablesorter'> <thead> <tr style='font-weight:bold;'><td></td><th>Date</th><th>Name</th><th>Town</th></tr> </thead> <tbody> <tr><td>0

我有以下表格:

<table class='tablesorter'>
<thead>
<tr style='font-weight:bold;'><td></td><th>Date</th><th>Name</th><th>Town</th></tr>
</thead>
<tbody>
<tr><td>04.08.2013</td><td>Martin</td><td>Chicago</td></tr>
<tr><td>04.08.2013</td><td>Justin</td><td>Washington</td></tr>
<tr><td>04.08.2013</td><td>Paul</td><td>Berlin</td></tr>
<tr><td>04.08.2013</td><td>Penny</td><td>Prague</td></tr>
</tbody>
</table>

DateNameTown
2013年8月4日马丁奇卡戈
2013年8月4日华盛顿
2013年8月4日柏林
2013年8月4日彭尼普拉格
我使用以下Tablesorter设置:

<script type="text/javascript" id="js">
 $(document).ready(function() {     
    $("table").tablesorter({
        sortList: [[1,1]]
         headers: { 
                    1: {sorter:"dd.mm.yyyy"}        
              }         
    });
    $.tablesorter.addParser({
        id: "dd.mm.yyyy",
        is: function(s) {
            return false;
        },
        format: function(s) {
            s = "" + s;
            var hit = s.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);
            if (hit && hit.length == 4) {
                return hit[3] + hit[2] + hit[1];
            }
            else {
                return s;
            }
        },
        type: "text"
    }); 
});
</script>

$(文档).ready(函数(){
$(“表”).tablesorter({
排序列表:[[1,1]]
标题:{
1:{分拣机:“dd.mm.yyyy”}
}         
});
$.tablesorter.addParser({
id:“dd.mm.yyyy”,
is:功能{
返回false;
},
格式:函数{
s=”“+s;
var hit=s.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);
if(hit&&hit.length==4){
回击[3]+命中[2]+命中[1];
}
否则{
返回s;
}
},
键入:“文本”
}); 
});
对于以dd.mm.yyyy格式对带有日期的列进行排序很好,但对于自定义用户排序,我还需要“排序箭头”,如

有什么想法吗

谢谢


注意:对不起,我的英文是:)

尝试将
$.tablesorter.addParser
函数放在document ready函数之外(初始化表之前):


$.tablesorter.addParser({
id:“dd.mm.yyyy”,
is:功能{
返回false;
},
格式:函数{
s=”“+s;
var hit=s.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);
if(hit&&hit.length==4){
回击[3]+命中[2]+命中[1];
}否则{
返回s;
}
},
键入:“文本”
}); 
$(函数(){
$(“表”).tablesorter({
sortList:[[1,1]],//在此处添加缺少的逗号!
标题:{
1:{分拣机:“dd.mm.yyyy”}
}         
});
});

尝试将
$.tablesorter.addParser
函数置于document ready函数之外(初始化表之前):


$.tablesorter.addParser({
id:“dd.mm.yyyy”,
is:功能{
返回false;
},
格式:函数{
s=”“+s;
var hit=s.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);
if(hit&&hit.length==4){
回击[3]+命中[2]+命中[1];
}否则{
返回s;
}
},
键入:“文本”
}); 
$(函数(){
$(“表”).tablesorter({
sortList:[[1,1]],//在此处添加缺少的逗号!
标题:{
1:{分拣机:“dd.mm.yyyy”}
}         
});
});
<script>
$.tablesorter.addParser({
    id: "dd.mm.yyyy",
    is: function(s) {
        return false;
    },
    format: function(s) {
        s = "" + s;
        var hit = s.match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);
        if (hit && hit.length == 4) {
            return hit[3] + hit[2] + hit[1];
        } else {
            return s;
        }
    },
    type: "text"
}); 
$(function() {     
    $("table").tablesorter({
        sortList: [[1,1]], // add the missing comma here!
        headers: { 
            1: {sorter:"dd.mm.yyyy"}        
        }         
    });
});
</script>