You will often want to create a list with a filter. However, often what you want is a default filter position when you show the list. In the following example we are filtering employees by country and we want the default view to show countries from USA only and from there the user can make their own section. Here is how you achieve creating a default filter. Thanks @adam for contributing this tip.
YAML Snippet for this tip follows below:
query: |
SELECT id
,'$.EmployeeID'
,'$.LastName'
,'$.Address'
,'$.City'
,'$.State'
,'$.Country'
,'$.Department'
,'$.FirstName'
,'$.Position'
,'$.Salary'
,'$.ZipCode'
FROM [default/employees]
WHERE '$.Country' like @filter
order by '$.LastName'
queryParameters:
filter: |
=$boolean(@ctx.components.empList.state.filter) ? @ctx.components.empList.state.filter : 'USA'
children:
- type: component.list
instanceId: empList
options:
data: =@ctx.datasources.employees
filter:
- title: USA
value: USA
- title: Canada
value: Canada
The query parameter (filter) checks if the filter control exists and if it does we just use it. If not. Then we set the default which in this case is ‘USA’.