Comment on page
Filters and Conditions
Use Adalo's built-in logic operators to filter records, create conditional actions, or change a component's visibility
Skill Level: Beginner
Filters and conditions can be found in many of Adalo's components. Knowing how to use them effectively can open up a world of possibilities no matter where you use them! First let's define each term. Both of them run on what's called If-Then logic, meaning that if something is true, then do this thing.
- Filters - These are used to, you guessed it, filter records that are being pulled from the database. It usually involves starting with lots of records and narrowing it down to just a few using the pre-programmed logic Adalo has available.
- Conditions - These also use this pre-programmed logic, but instead of filtering records, conditions evaluate whether or not something should occur. In this case, we're working with only one record at a time. Conditions actually contain a filter to help make this possible.
Filters are typically found in List components and components that display whole groups of records such as:
- Deck Swiper
- Image Swiper
- Chart Kits
- ...and many more!
Conditions are typically found primarily in two places:
You can add a filter anywhere you see the +Filter or the +Add Another Filter button. In Lists, Charts, and other components you will notice that 1 filter is provided by default, but you can also add Custom Filters to combine logic and display very specific groups of records:
Filter Shown in a List or Chart -->
Filter Shown in a Count -->
Within filters you have the option to make custom filters be inclusive of each other, or exclusive of each other. For lists and charts that have multiple custom filters, you can choose whether all of those filters must be true in order to show records, or you can choose whether any of the filters are true. You can do this using the AND and OR logic for filters. In the example below, the Drops to be displayed in the list must both have NFT in the title and have Published set to true. More filters can be added, by clicking on the + AND button. In order for records to display, all of the filters joined with AND must be met.
You can also create filters using OR. In the example below, only the Drops with NFT or ETH in the title will be shown. Notice that you can still add AND filters within each group of filters and still have an OR filter as well. This makes it very easy to dial in specific groups of records to display!
There are two main places where you can add conditions. One is in a component's visibility options and the other is in an action's advanced settings. For components visibility you can click on the more button for the component, then click on Change Visibility. To access conditional actions, just click on Show Advanced in the bottom of the action.
Accessing the conditional visibility -->
Accessing conditional actions -->
After clicking on these, you will see the dropdown option to make the visibility or action only happen either Always or Only Sometimes. If you set it to Only Sometimes, a filter will appear where you can use logic operators to determine when or if something should be shown or occur. In the example below, the action will only occur if the Logged In User is marked as an Admin in the database:
Logical operators is just a fancy way of saying how Adalo determines what records to show or when something like visibility or an action should occur. They result in either being true or false - for example, either Adalo should (true) show records based on this operator or it should not (false). Both filters and conditions use operators to determine what do to with records, components, or actions.
Following the if-then logic mentioned earlier we can use logical operators within filters and conditions to instruct Adalo that "if this thing is true, then do this other thing". In the example below we are using the "Is equal to" operators to evaluate a text field (Email) to say we should only display a component if the Logged In User's email is equal to [email protected].
There are several types of operators, depending on the property types being compared. Explore the tabs below to see the operators for each database property type:
- Is equal to - This operator is case sensitive and the two pieces of text must match each other exactly - even if there is a hidden return or space in the text. This operator is very strict."Day" is equal to "day" = false "Day" is equal to "Day" = true
- Is not equal to - This operator is also case sensitive and determines if the two pieces of text are different from one another - even by a space or return. This operator is very strict. Hint: it's often easier to exclude items that to determine if they match exactly."Day" is not equal to "day" = true Day is not equal to Day = false
- Contains - This operator determine if a string of text contains another string of text. This operator is not very strict and not case sensitive, but can sometimes have unintended consequences if multiple records share the same text string. For example, [email protected] and [email protected] both contain "gmail" but they are not the same result. This also makes it great for searching for records in your app.Day contains day = true Day contains Day = trueTuesday contains Day = true
- Is equal to - Determines if two number values are equal to each other. This operator is very strict - down to decimals. Can also handle negative numbers.4 is equal to 4 = true 4 is equal to 3 = false
- Is not equal to - Determines if two number values are not equal to each other. This operator is very strict - down to decimals. Can also handle negative numbers.4 is not equal to 4 = false 4 is not equal to 3 = true
- Is greater than - Determines if one number value is greater than another. This operator is very strict - down to decimals. Can also handle negative numbers.4 is greater than 4 = false 4 is greater than 3 - true
- Is greater than or equal to - Determines if one number value is greater than OR equal to another. This operator is strict - down to decimals. Can also handle negative numbers.4 is greater than or equal to 4 = true 4 is greater than or equal to 3 = true
- Is less than - Determines if one number value is less than another. This operator is very strict - down to decimals. Can also handle negative numbers.4 is less than 4 = false 4 is less than 3 = false
- Is less than or equal to - Determines if one number value is less than OR equal to another. This operator is very strict - down to decimals. Can also handle negative numbers.4 is less than or equal to 4 = true 4 is less than or equal to 3 = false
- Is between - Determines if a number value is between two other number values. The first value provided is included in the range, the second value provided is excluded from the range. The operator is very strict - down to decimals. It can also handle negative numbers.4 is between 4 and 6 = true 6 is between 4 and 6 = false5 is between 4 and 6 = true
- Is after - Determines if one date property or datetime property occurs after another. You can compare dates and datetimes interchangeably.Aug 12, 1992 4:00PM is after Aug 12, 1980 = true
- Is before - Determines if one date property or datetime property occurs before another. You can compare dates and datetimes interchangeably.Aug 12, 1992 4:00PM is before Aug 12, 1980 = false
- Is between - Determines if one date or datetime property occurs between two other dates or datetimes. The first datetime provided is inclusive, but the second datetime is exclusive. You can compare dates and datetimes interchangeably.Aug 12, 1992 4:00PM is between Aug 12, 1980 and Aug 12, 2021 = trueAug 12, 1980 4:00PM is between Aug 12, 1980 and Aug 12, 2021 = trueAug 11, 1980 4:00PM is between Aug 12, 1980 and Aug 12, 2021 = false
The only type of relationship that can be compared with logical operators in Adalo are one-to-many relationships. You cannot compare many records with many other records.
- Contains - Determines if a group or collection of records contains a selected record. This operator evaluates the record as a whole instead of just a single property like the others.
- Does not contain - Determines if a group or collection of records does not contain a selected record. This operator evaluates the record as a whole instead of just a single property like the others.
- Is true - Determines if a true/false property is checked
- Is false - Determines if a true/false property is not checked
- You can even combine filters with the power of conditions to give even more control over what happens in your app. For instance, you may change the visibility of a component based on a filtered count of a collection of records in your database.
- Currently conditional actions and conditional visibility can only have one filter attached to them, but filters for lists, counts, charts, and other components can have as many filters as you like.
- If you have multiple filters on the same component or count, those filters use an AND logic, meaning that all the filters must be true in order for the record(s) to be shown. OR logic is something we are considering adding, but is not currently available at this time.
- Many times conditional actions and conditional visibility can be used interchangeably to achieve the same end result or user experience even though the setup may differ slightly.