How to Sort Dynamic Lists with Multiple Sort Options in Webflow

Published on
May 4, 2020

Sorting Dynamic Lists with Multiple Sort Options in Webflow

Webflow is an amazing platform that allows you to create beautiful and functional websites without the need for coding. One key feature of Webflow is its ability to handle dynamic content with ease through the CMS library. In this tutorial, we will focus on sorting through a dynamic list with multiple sort options using the F and Sweet CMS library for Webflow. We will walk through a live example to understand how to achieve this functionality in Webflow without writing a single line of code.

Setting up the Live Example

In the live example we will be using the combined component along with the sort component to sort through multiple dynamic lists. Imagine combining five different collection lists into one single list and being able to sort through all five of those lists since they are now part of one single list wrapper.

The Sorting Component

Let's dive into the sorting functionality. In this example, we will have four options to sort by: project number, color, year, and service. It's important to note that only one sort option can be applied at a time. By using the sort component, we can easily sort the dynamic list based on the selected criteria.

The Designer View

In the designer view, the combined component plays a crucial role in combining the different collection lists into one single list. Without this, there would be layout issues when attempting to sort through the list. The buttons used for sorting all have a common class named filter button. The magic happens through the data attribute of sort by, which specifies the class name to be sorted by.

For instance:

  • The project number filter button has a sort by class name.
  • The color filter button has a color class for sorting by color.
  • The year filter button has a year class for sorting by year.
  • The service filter button has a service class for sorting by the service name.
  • It's crucial to ensure that the collection list element has a class specified, such as collection-list, for the sorting to function correctly.

Custom Code

Moving to the custom code section, we will add the F and Sweet CMS library to the page. This library will enable us to handle the sorting functionality. Additionally, we will include project-specific scripts which will run a function to create a new AFS library instance targeted to the collection list.

The custom code should cover:

  • Adding the F and Sweet CMS library to the page.
  • Creating a new AFS library instance targeted to the collection list.
  • Combining all lists with the collection list class.
  • Sorting the combined list based on the selected criteria.

Summary

In conclusion, Webflow's F and Sweet CMS library allows us to seamlessly sort through multiple dynamic lists using the combined and sort components. By implementing the necessary classes and data attributes, along with custom code, we can achieve advanced sorting functionality without the need to write complex code.

Webflow empowers users to create dynamic and interactive websites with ease, and the F and Sweet CMS library is a powerful tool for handling dynamic content within Webflow projects. With the knowledge gained from this tutorial, you can confidently implement advanced sorting functionality in your Webflow projects without encountering layout issues or resorting to custom code.

So there you have it! Sorting through a dynamic list with multiple sort options in Webflow is now within your reach, thanks to the powerful features provided by Webflow's CMS library and the convenience of its visual development environment.