Relative Filters
Relative Filter allows you to filter a collection element based on the context of the page or the logged-in user.
What is a Relative Filter?
A Relative Filter allows you to filter a collection element based on the context of the page or the logged-in user. This means you can dynamically display records that are relevant to either the current user or the specific record you are viewing.
For example, if you're on a Project record page and want to display tasks that belong to that project, a relative filter enables you to filter tasks based on the project being viewed. This makes it easy to create customized views based on real-time context within your app.
When to Use a Relative Filter
Relative filters are ideal in scenarios where the data displayed needs to be dynamic and specific to either:
The Logged-in User (e.g., "My Tasks" or "My Orders")
The Record Page (e.g., tasks linked to a specific project, comments on a specific post)
Some common use cases include:
Showing only tasks that belong to the logged-in user
Displaying only the orders or items relevant to the user currently viewing their dashboard
Filtering related records, such as showing only comments tied to a specific blog post, or tasks linked to a project.
What to Do If You Don't See the Option You Want
If you're setting up a relative filter and can’t find the field or option you expect, here are some steps to troubleshoot:
Check Relationships: Ensure that there is a relationship between the collection you want to filter and the record you’re viewing or the logged-in user. For example, to filter tasks by a project, the tasks need to have a relationship field that links them to a project. Tip: add a lookup or another linked field if there isn't a direct link
Verify Data Source: If you're using an external data source like Airtable or PostgreSQL, make sure the necessary relationships are properly set up within the data source and synced correctly with your Noloco app.
Page Type: Ensure you are on a Record page or logged in as a user to trigger the available relative filters. The options only appear if the page has the appropriate context.
If none of these resolve the issue, consult your field mappings or reach out to Noloco support.
Combining Relative Filters with Record Value Filters
Relative filters can be combined with static value filters to create highly specific views. For instance, you can:
Filter tasks to show only those assigned to the logged-in user and that have a status of "in progress."
Display orders related to a specific customer record but limit the view to orders placed in the last 30 days.
Combining these filters allows for flexibility and deeper customization of the data shown within your app, ensuring that users only see what is most relevant to them.
When to Use Relative Filters vs Permissions
Both relative filters and permission rules allow you to control what records a user can see. However, there are distinct use cases for each:
Relative Filters: These are great for filtering data in specific views, such as showing only the tasks related to a logged-in user or record. However, they don't prevent access to the records—just whether they are displayed in that particular view.
Permissions: If you need to restrict access entirely, you should use record-level permissions. These permissions operate at the database level and prevent unauthorized users from viewing or accessing specific records, regardless of filters. For example, if a user shouldn't access certain financial records, permission rules will ensure that they cannot view or manipulate those records in any context.
In summary, use Relative Filters for display-level filtering and Permissions when you need to limit access to records themselves.
FAQs
Q: Can I use a relative filter if my data source is external (e.g., Airtable or PostgreSQL)? A: Yes! As long as you’ve created the necessary relationships between your collections and the Noloco User table, or your external data source's user table is properly linked, you can apply relative filters based on the logged-in user or the current record page.
Q: Do relative filters affect data access at the API level? A: No, relative filters only control the display of records within the user interface. To control data access at the API level, you need to set up record-level permissions.
Q: What if the user shouldn’t even be able to see the records filtered out by a relative filter? A: In that case, you should use record-level permissions to restrict access entirely. Filters only control visibility within a specific view and don't prevent access to the records behind the scenes.
Last updated