jQuery表格排序代码只能在Mozilla Firefox中使用 [英] jQuery table sort code only working in Mozilla Firefox

查看:77
本文介绍了jQuery表格排序代码只能在Mozilla Firefox中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用charlietfl的答案在StackOverflow中对这个问题进行排序从1月到12月,我的HTML表中的月份列。我只是修改了一些东西,所以我可以在我的网站上使用它。我也在使用 tablesorter ,所以我可以按字母顺序对其他表格列进行排序。问题是它只适用于Mozilla Firefox。其他浏览器不会对月份列进行排序。有时候
包裹表格标题的tr跳出了标签并进入tbody标签。以下是我的表格: http://makzel.com/problems/

I used charlietfl's answer to this question in StackOverflow to sort the months column in my HTML table from January to December. I just modified a few things so I could use it on my Website. I am also using tablesorter so I could sort the other table columns alphabetically. The problem is that it only works on Mozilla Firefox. Other browsers won't sort the months column. Sometimes the tr that wraps the table headers jump out of the thead tag and goes inside the tbody tag. Here's my table: http://makzel.com/problems/

什么可能导致这种情况?

What could be causing this?

这是我完整的jquery代码:

Here's my full jquery code:

(function($) {

    'use strict';

    var $window = $(window);

    $window.ready(function(){

        // Enable sorting for tables
        $(".tablesort").tablesorter({
            headers: {
                0: {
                    sorter: false
                }
            }
        }); 

        // Sort by month
        $('.tablesort th').click(function(){
            var sorters =['January','February','March','April','May','June','July','August','September','October','November','December']

                    var $rows = $('tr:gt(0)').sort(function(a, b){
                        var aSrcIdx =sorters.indexOf( $(a).find('td:first').text() );
                        var bSrcIdx = sorters.indexOf( $(b).find('td:first').text());

                        return aSrcIdx >  bSrcIdx;    
                    });

            $(this).closest('.tablesort').append($rows);
        });

        // Tablesort header background change on click
        $(".tablesort th").click(function(){
            $('.tablesort th').not(this).removeClass('sorted');
            $(this).toggleClass('sorted');
         });

        function postOverflow() {
            if ($window.width() < 768) {
                $('.tablesort').closest('.post').css("overflow","scroll");

            } else{
                $('.tablesort').closest('.post').css("overflow","none");
            }
        }
        postOverflow();
        $window.resize(postOverflow);

    }); // Ready

})(jQuery);

下面是链接,它显示tr标签跳出标签: http://cms5.revize.com/revize/haddonfield/departments/table_sort_test/index.php

Here's the link of it showing the tr tag jumping out of the thead tag: http://cms5.revize.com/revize/haddonfield/departments/table_sort_test/index.php

推荐答案

根据 低于 b ,0让它们保持不变,或者1将 b 放在 a
尝试替换:

According to the documentation of array.sort, try returning -1 to put a below b, 0 to leave them unchanged, or 1 to put b below a. Try replacing:

return aSrcIdx > bSrcIdx;    

with

with

return aSrcIdx < bSrcIdx ? -1 : bSrcIdx < aSrcIdx ? 1 : 0;    

这篇关于jQuery表格排序代码只能在Mozilla Firefox中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆