In this documentation, we refer to “select parameters” as single-select and multi-select parameters. Non-select parameters are DateParameter, NumberParameter, TextParameter, etc.
Overview
In Squirrels, a parameter’s available options can be filtered (or “cascaded”) based on two mechanisms:- Parent parameter cascading: A child parameter’s options depend on what the user selects in a parent parameter
- User attribute cascading: A parameter’s options depend on attributes of the authenticated user
Parent-child cascading
Parent-child cascading allows you to link parameters so that the available options in a child parameter change based on what is selected in the parent parameter.Basic example
Consider a scenario where you have a “Country” dropdown and a “City” dropdown. You only want to show cities that belong to the selected country:pyconfigs/parameters.py
How it works
The cascading mechanism works through two key components:parent_name: Specified in the factory method (create_with_optionsorcreate_from_source), this identifies which parameter is the parentparent_option_ids: Specified in each parameter option, this lists which parent option IDs make this option visible
- Gets the selected option(s) from the parent parameter
- Filters child options to those where
parent_option_idsintersects with the parent’s selected IDs - Returns only the matching options to the user
Multiple parent option IDs
A child option can be associated with multiple parent options. For example, a region that spans multiple countries:For select parameters, each parent option ID can appear in zero or more child options. This means:
- A parent option might have no corresponding child options
- A parent option might have many corresponding child options
- A child option can belong to multiple parent options
Using data sources
When parameter options come from a database table, useparent_id_col in the data source to specify cascading:
pyconfigs/parameters.py
Cascading for non-select parameters
While select parameters cascade their list of options, non-select parameters (DateParameter, NumberParameter, etc.) cascade their configuration. This allows you to change defaults, constraints, and ranges based on parent selections.Example: Date parameter with cascading constraints
pyconfigs/parameters.py
Rules for parent parameters
Not all parameter types can be parents. The rules are:| Child parameter type | Allowed parent types |
|---|---|
| Select parameters | SingleSelectParameter or MultiSelectParameter |
| Non-select parameters | SingleSelectParameter only |
User attribute cascading
User attribute cascading filters parameter options based on an attribute of the authenticated user. This is useful for role-based access control or personalization.Basic example
pyconfigs/parameters.py
access_level="guest" makes a request, they only see the “Summary Report” option. A member user would see “Summary Report” and “Detailed Report”, while an admin user would see all three options.
How it works
The user attribute cascading mechanism works through two components:user_attribute: Specified in the factory method, this identifies which user attribute to checkuser_groups: Specified in each parameter option, this lists which attribute values make this option visible
- Gets the value of the specified attribute from the authenticated user
- Filters options to those where
user_groupscontains the user’s attribute value - Returns only the matching options to the user
Using custom user fields
If you define custom fields inpyconfigs/user.py, you can use them for cascading by prefixing with custom_fields.:
pyconfigs/parameters.py
Same rules apply
The same rules that apply to parent-child parameter cascading also apply to user attribute cascading:- For select parameters: Each user group value can appear in zero or more options
- For non-select parameters: Each user group value can appear in at most one option
Using data sources
When parameter options come from a database, useuser_group_col:
pyconfigs/parameters.py
Combining parent and user attribute cascading
You can use both parent cascading and user attribute cascading on the same parameter:pyconfigs/parameters.py
When combining both cascading types for non-select parameters, each unique combination of (parent_option_id, user_group) can appear in at most one child option.
Disabled parameters
A parameter becomes disabled when it has no available options after filtering. This can happen when:- The parent parameter’s selection doesn’t match any
parent_option_idsin the child’s options - The user’s attribute value doesn’t match any
user_groupsin the parameter’s options
Checking for disabled parameters
Incontext.py or data models, use sqrl.param_exists() to check if a parameter is enabled:
pyconfigs/context.py
Summary
| Feature | For select parameters | For non-select parameters |
|---|---|---|
| Parent must be | SingleSelectParameter or MultiSelectParameter | SingleSelectParameter only |
| Options per parent ID | Zero or more | At most one |
| Options per user group | Zero or more | At most one |
| Cascades | List of selectable options | Configuration (defaults, constraints) |
Related pages
- Widget parameters - Configure parameters in Python
- Parameter - See all available parameter types here
- SingleSelectParameter - Single-select parameter reference
- MultiSelectParameter - Multi-select parameter reference
- DateParameter - Date parameter reference
- SelectParameterOption - Options for select parameters
- DateParameterOption - Options for date parameters