Using MixItUp jQuery filtering plugin 
with Dynamic content in Webflow

Category-4
Category-3
Category-2
Category-2
Category-3
Category-5
Category-1
Category-2
Category-3
Category-1
Category-4
Category-5
Category-1
Category-3
Category-2
Category-4
Category-3
Category-1
Category-1
Category-3
  1. Creating content and structure for filtering

    As you know, MixItUp plugin filters and sorts content inside of a container

    So, creating content structure for filteringDynamic Collections will be pretty similar to the tutorial with static content (look tutorial). 

    First of all - create Dynamic Collections.

    Here we assume that we have collection of ITEMS (it may be blogposts, images, articles, etc. ) and CATEGORIES for that items.
    _


    Inside of ITEM collection structure should be a reference field, connected to the CATEGORY collection



    Next step - Add both collections to the page.

     Remind you, that MixItUp plugin filters and sorts content inside of a container. 
    Container should have a unique ID that MixItUp will use to reference it.
    By default, plugin will look for elements to filter and sort within your container with the class ’.mix


    So we will give ID #container to the Dynamic List and class '.mix' to the Dynamic item. Inside of each item we will add text field and connect its data to the reference field "Category". In this example I give class '.categ' to this field (later we will use this class name in the code snippet).

    * After you will make sure that filtering works, you can make this text field display: none *
    _


    For the filtering menu we will use Dynamic list "Categories" and one static button for show "All" items.

    In this example I wrap static button and dynamic list in the div, which styled using flexbox.

    By default MixItUp will apply filtering click handlers to any clickable element with the class ’.filter’, so all dynamic items and static button we give the same class '.filter'

    Also, dynamic items will contain buttons (or text-links or link-blocks with text, which you prefer).

    For the further connecting this dynamic list to the code snippet
    we are going to set theID for it: #dyn-filter-menu
    _


    Final structure will look like this:
    _

  2. Adding data attributes for make filters work

    Each filter button requires the attribute data-filter containing a class of the elements you wish to show.

    For the static button we will add custom data attribute on the settings tab:

    Data-attributes for the dynamic list will be added by jQuesry code snippet

  3. Connecting plugin

    For connect this plugin you will have to add custom code to the site settings (pic1) or page settings (pic2) before </body> tag.



    First we link to .js file of plugin.

    You can either host MixItUp yourself (hosting server or dropbox or google-drive) 
    or load it by using public CDN link  or get public link to plugin file.

    <script src="your link" type="text/javascript"></script> 

    In my case I used public link
    http://cdn.jsdelivr.net/jquery.mixitup/latest/jquery.mixitup.min.js


    After this line of code we will add the jQuery script snippet which will contain:

    - Creating dynamic items classes from its categories (for the items)

    $('.w-dyn-item .categ').each( function(index, element) { var _this = $(element); var text = _this.text(); var select = text.indexOf(' ') == -1 ? text.length : text.indexOf(' '); var className = text.substr(0, select); _this.parent().addClass(className.toLowerCase()); } ); Here we use class of that text field with the category name (reference field). Don't forget to change '.categ' if you used different class name.

    - Adding data-filter attributes for dynamic filters (for the categories)

    $('#dyn-filter-menu > div').each( function() { var catName = "." + $(this).children('a').text(); $(this).attr('data-filter', catName.toLowerCase()); }); Here we used ID of dynamic list "Categories". Don't forget to change '#dyn-filter-menu' if you used different ID.

    - Initializing MixItUp plugin when page is loading

    $(document).ready(function() { $(function(){ $('#container').mixItUp(); }); }); Don't forget to change #container if your will use another ID.

    Full code snippet will look like this:

  4. Last important detail.

    Before we get to the finish, there is one small but crucial CSS rule you must add to the project:

    filtering elements should have setting display:none
    So, do not forget to apply display:none to class .mix before publish the site

    When MixItUp plugin will load, it will add the display value as an inline-style (the default is “inline-block”).

  5. Publish you site and enjoy plugin!
    Good luck!