mixitup counting visible items on initial start after page loading

梦想与她 提交于 2021-01-29 03:26:50

问题


I am playing with mixitup to sort items.

I can count items visible after I press a sort or filter buttons:

$('#collection').on('mixEnd', function(e, state){
    var countvisible = $("#container> tr[style='']").length;
    console.log('Sorted! ' + countvisible );

    $('#current_count').text(countvisible);
});

What I need: get a count of visible items on page load

but the `on('mixEnd') does NOT ignite during the initialization of the mixitup on page load.

How to do it? I can just use on PageLoad sit some delay, but it doesn't seem as a good practice.

Any help appreciated.


回答1:


I know it's a little late, but if it can help, I found the answer in this codepen.

It's a huge one, but in your case, you would only need this:

$('#collection').on('mixEnd', function(e, state) {
    $('#current_count').html(state.totalShow);
});

The state.totalShow is the key ;)




回答2:


Do you try to use the visible selector ?

$('#collection').on('mixEnd', function(e, state){
    var countvisible = $("#container> tr[style='']:visible").length;
    console.log('Sorted! ' + countvisible );

    $('#current_count').text(countvisible);
});


来源:https://stackoverflow.com/questions/41197503/mixitup-counting-visible-items-on-initial-start-after-page-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!