Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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:按日期排序同位素_Jquery_Html_Sorting_Jquery Isotope - Fatal编程技术网

jQuery:按日期排序同位素

jQuery:按日期排序同位素,jquery,html,sorting,jquery-isotope,Jquery,Html,Sorting,Jquery Isotope,我正在按日期对div网格进行排序,但遇到了一个问题。div是按日期排序的,但当您引入另一个月时,它不考虑这一点,只按天值排序。 HTML: 因此,正在对块进行排序,但最后一个日期为0562013的块将首先出现,因为05是我假设的最小数字,是否还需要考虑月份,以便成功地按日期对div进行排序?您需要更改日期格式。现在的情况是,你无法区分天和月:2122013可能是2.12.2013也可能是21.2.2013 jQuerycontainer.imagesLoaded( function(){ jQu

我正在按日期对div网格进行排序,但遇到了一个问题。div是按日期排序的,但当您引入另一个月时,它不考虑这一点,只按天值排序。

HTML:


因此,正在对块进行排序,但最后一个日期为0562013的块将首先出现,因为05是我假设的最小数字,是否还需要考虑月份,以便成功地按日期对div进行排序?

您需要更改日期格式。现在的情况是,你无法区分天和月:
2122013
可能是
2.12.2013
也可能是
21.2.2013

jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
    filter: hashfilter,
    itemSelector: '.grid-block',
    getSortData : {
    date : function( jQueryelem ) {
    return date.substring(4,8)+date.substring(2,4)+date.substring(0,2);
    }
    },
    sortBy : 'date',
    animationEngine: 'css',
    masonry: {
    columnWidth: 4
    }

});
});
我建议使用通用的
Y-M-D
(年-月-日,例如
2013-03-07
)格式。

默认情况下它是可排序的。您不需要更改任何其他内容

这似乎不起作用,似乎没有按日期对div排序?我也尝试了编辑过的一个,似乎按随机顺序对div排序。我看到您已将其更改回上面的版本,我已尝试使用它,但仍然无法使其正常工作?您可以通过将0添加到月份来更改生成日期的方式吗?我可以在本页上,是的。我已经改变了php,现在生成的日期有前导零,现在有没有办法成功地按日期排序?我编辑了答案以实现您的目标。顺便说一下,如果您可以根据需要生成日期,那么直接从php页面以这种格式(yyyymmdd)返回值就更容易了。(您不需要这种javascript改编)
 jQuery(document).ready(function(){

var jQuerycontainer = jQuery('#main-grid');

if(location.hash!=""){
    var hashfilter = "." + location.hash.substr(1);
    }
    else{
    var hashfilter = "*";
    }

jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
    filter: hashfilter,
    itemSelector: '.grid-block',
    getSortData : {
    date : function( jQueryelem ) {
    return jQueryelem.attr('data-category');
    }
    },
    sortBy : 'date',
    animationEngine: 'css',
    masonry: {
    columnWidth: 4
    }

});
});

jQuery('.filter-menu a').click(function(){
    var selector = jQuery(this).attr('data-filter');
    var prettyselector = selector.substr(1);
    location.hash = prettyselector;
    jQuery('html, body').animate({scrollTop:0}, 'slow');
    return false;
    });

jQuery('.grid-filter a').click(function(){
    var selector = jQuery(this).attr('data-filter');
    var prettyselector = selector.substr(1);
    location.hash = prettyselector;
    jQuery('html, body').animate({scrollTop:0}, 'slow');
    return false;
    }); 

jQuery(window).hashchange(function(){

                if(location.hash!=""){
                    var hashfilter = "." + location.hash.substr(1);
                }
                else{
                    var hashfilter = "*";
                }


jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
    filter: hashfilter,
    itemSelector: '.grid-block',
    getSortData : {
    date : function( jQueryelem ) {
    return jQueryelem.attr('data-category');
    }
    },
    sortBy : 'date',
    animationEngine: 'css',
    masonry: {
    columnWidth: 4
    }
});
});
});
});
jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
    filter: hashfilter,
    itemSelector: '.grid-block',
    getSortData : {
    date : function( jQueryelem ) {
    return date.substring(4,8)+date.substring(2,4)+date.substring(0,2);
    }
    },
    sortBy : 'date',
    animationEngine: 'css',
    masonry: {
    columnWidth: 4
    }

});
});