Isotope: reset all combination filters

前端 未结 2 1326
臣服心动
臣服心动 2021-02-05 16:57

I have an isotope combination filter setup with a number of data-filter-group\'s, each with a rest/show all list item:

  • 2条回答
    •  情深已故
      2021-02-05 17:54

      I was looking for something similar, thought I would put the answer on here just in case another searcher came across this question. My problem with the solution the poster mentioned is that for me at least, it didn't do a true reset. I wanted the buttons to reset as well as the filter. Also I was getting a strange bug where after hitting the reset button, my filters weren't acting right.

      The script below solved all my problems (at the date of this answer, lol). Source: https://github.com/metafizzy/isotope/issues/928

        var $anyButtons = $('.filters').find('button[data-filter=""]');
        var $buttons = $('.filters button');
      
        $('.button--reset').on( 'click', function() {
          // reset filters
          filters = {};
          $grid.isotope({ filter: '*' });
          // reset buttons
          $buttons.removeClass('is-checked');
          $anyButtons.addClass('is-checked');
        });
      

    提交回复
    热议问题