One of the most common asks is to be able to search CDS records in a Gallery control in real-time using a Text-box.
Search Box & Gallery connected to CDS
Let’s design a simple gallery that is populated with CDS records from Account entity.
- Take a Text Input control (Textbox) and make it look like a Search Box.
In order to have the Search watermark, write the text to appear as water-mark, enter it in Hint text property of the Text input
- Take a Gallery control and select Data Source as Accounts from CDS.
The way the above shown Gallery control is populated is by selecting a CDS Data Source which is as below –
Finally, there’s a 1-line formula that will do the trick for you
- In the Items property of the CDS Gallery, I have to filter the records based on the Text of the Text Input on my form.
Marked by green arrow Filter() function is the one which handles filtering of the data set based on the parameters demanded by the method. Here’s Microsoft Docs on the same – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-filter-lookup
Underlined by red Accounts is the CDS data source which I want to filter on.
StartsWith() is a method which is used to compare the start of the string in question. In this case, the text I enter in the SearchField textbox.
1. ‘Account Name’ is the field in the Accounts dataset to be considered on which the search parameter is dependent.
2. Underlined by purple SearchField.Text in which SearchField is the textbox which is used to query the Name of the Account and .Text is Text value of the string which will be considered.
So at all times, whenever there’s a change in the Textbox value, the Items of the Gallery control are supposed to be updated with the filtered records.
Now, when you use the App, here’s what it will behave like. As you type, the records will filter with a certain delay (depending on how large your dataset is)
Hope this was useful!!
Here are some more Canvas Power Apps posts you might want to check –