Filter & Search Data:
Define Data Source Filter
Define Data Source Filter
Introduction
In this Tutorial we show you how to Filter i.e. "search" content in your app.
Filtering is central on how many apps display subset of the content. For example categories for news app are usually filtered content based on a 'category' section of a Data Source. Recipes, weather regions, movie or music genres all use filter to display the matching content.
This tutorial focuses on how to define filter for existing data sources.
Consult : Using Query Parameters to learn how to add parameters on a Live Data Source.
Overview
The Filtering will depend on your App Data architecture. If data is stored in a Local SQL Database or comes from a Live Feed (Remote) impacts how Filter work.
- Filter from a Cloud Collection or Live data feed (XML,..)
- Filter for an On device Local SQL Data Base
- Difference between Filtering On Device and Live Feed
Tutorial App: Filter Data
Instal the Tutorial App 'Filter Data' from the Base AppTutorial section on your Dashboard.
The content of this app comes from a Cloud Collection named "Apple and Oranges" which is installed along with the Tutorial App.
This video Tutorial shows you how the app is set up:
Filter from a Cloud Collection, RSS, JSON or XML Data Feed
Filter from a Cloud Collection or Live Feed
The Action "Define a Data Source Filter" allows you to filter content from a data source.
The Filtering always apply to the column of the Cloud Collection or a field of a Live Feed (XML, JSON, ..)
This is not limited to Cloud Collection it works exactly the same for a Data Feed (RSS, XML, JSON, ...).
Filters are applied to the content of the node of a Data Source.
In our example we to use the column "Type" and filter based on the word "Orange" to sort the Oranges from the Apples.
When using the 'Define a Data Source Filter' action on a Cloud Collection or Live Data Feed (RSS, ...) we directly enter the value we want to search in the 'Value' field of the Define a Data Source Filter as it (NO QUOTE or anything else)
In our Tutorial App, the Action associated to the Button Orange is set as follow:
IMPORTANT : How to use multiple filter parameters?
The data source filters accumulate until the data source refreshes.
So you can call the Define a data source filter action several times with different parameters and then when the data source is refreshed ALL of those parameters will be sent to the server
Filter from an On Device SQL Database
Filter from an On Device SQL Database
The Action "Define a Data Source Filter" work for both Live Feed and On Device Local SQL Database.
When the Content is stored locally on the device the syntax of the Define a Data Source Filter search term change from 'Value' to ' Criteria'.
Check the screenshot below, you will notice that first
That is because we are actually executing a Search in a local SQL database.
Filters for local data sources (including local cloud collections) define conditions for the WHERE clause of a SQL statement.
In our example for "Criteria" we then use this term: ="Orange"
Write the '=' (equal sign) and adding " " (quotes) around the search term.
Very Powerful
Directly writing a SQL statement clause is extremely powerful (especially if you know SQL).
For example, if you wanted to to make a comparison case insensitive, you could set the data source filter to LIKE 'orange' (instead of = 'Orange'). You can also do partial matches, for example, LIKE '%rang%' would return all records that have "rang" anywhere in the field you're filtering on.
For example, if you wanted to to make a comparison case insensitive, you could set the data source filter to LIKE 'orange' (instead of = 'Orange'). You can also do partial matches, for example, LIKE '%rang%' would return all records that have "rang" anywhere in the field you're filtering on.
You can also compare values using inequality operators. If, for example, your cloud collection were tracking inventory, and you wanted to have a view in your app that showed which items had low stock, you could (assuming you have a column called quantity) set a filter on your quantity field, with a filter of < 5. That would return all items with a quantity less than 5.
Syntax difference between :
A Live Data Source and an On Device SQL Data base
The key difference is the syntax in value. Knowing that you are actually executing 2 very different actions.
- For a Live Data Source (XML, RSS, Cloud Collection) you enter the value as it without any quote.
- For an On Device SQL Data base (Local Data source) you actually write a WHERE clause of a SQL statement.
Referring to our 'Filter Data' Tutorial App
- Notice that the Data Source says 'Local Collection' (reffering to an on device SQL database
- Notice the quotes " around Orange and the equal sign. This is how you would write a WHERE clause for a SQL statement. (We are indeed searching a SQL database locally stored on the device)
Removing a Filer
To remove a Filter on a Local SQL Database or on a Live Feed (RSS, Cloud Collection, ..) simply use the action:
Remove Data Source Filter(s) Action
In our Tutorial 'Filer Data' app the 'All' button simply removes the Data Source Filter and refresh the List.
Learn More
- Using Query Parameters
- Data Architecture