No need to restrict a Power Apps Gallery search to a single method, multiple search options are possible.  This approach uses either cascading Dropdown Boxes to refine a search, or if you already know what you are looking for, type the search criteria directly in the Text Input box

Once either search option is selected, it supercedes and resets the other search option and is adopted by the Gallery control to filter it’s contents

 

Multiple Search Options

The same data on Countries from the previous post Power Apps Dropdown Boxes, is used in the demo below

Power Apps Search Function

Cascading Dropdowns

The AllowEmptySection property is set to true so both Dropdown boxes are blank when reset.  The first Dropdown Box gets the data from the Continent column, extracts just the distinct fields and sorts them alphabetically

 

Items: SortByColumns(Distinct(Country,Continent),"Result")

The second Dropdown box cannot be used until the first Dropdown box has a value.  Whether the first Dropdown has a value is determined by the Len (length) function and unless the value is greater than zero the Dropdown box is disabled.  IsBlank can be used instead of Len.  Once the first Dropdown box has a value, the second Dropdown takes the selection from the first Dropdown and uses it to present just those countries that are in the specified Continent

For more detail on the use of the SortByColumns and Filter functions see: Power Apps Dropdown Boxes     

DisplayMode: If(Len(Dropdown_Primary.Selected.Result)>0,DisplayMode.Edit,DisplayMode.Disabled)
Items: SortByColumns(Filter(Country,Continent=Dropdown_Primary.Selected.Result),"Title")

Search Text Box

The other  search option is straightforward, just a Text Input box with a blank Default property value

Reset

The Reset Button used the Reset function to change both the Dropdowns and the Text Input box to their default blank values

OnSelect: Reset(Dropdown_Primary);Reset(Dropdown_Secondary);Reset(TextInput_Primary)

Additionally, when the first Dropdown box is selected the Text Input box is reset and when the Text Input box is selected both the Dropdowns are reset.  This is done via the OnSelect property of each 

 

Gallery

The Gallery employs the nested If statements below for it’s Items property.  We already know that due to the resets, only the Dropdowns or the Text Input box can have a value at any one time

If the Text Input box contains a value, then this is used for the Gallery.  If only the first Dropdown has a value then this is used for the Gallery instead.  Finally, if the second Dropdown has a value, then a particular country has been selected and this is used to present a single record in the Gallery

If(
Len(TextInput_Primary.Text) > 0,
Filter(
Country,
StartsWith(
Title,
TextInput_Primary.Text
)
),
If(
Len(Dropdown_Secondary.Selected.Title) > 0,
Filter(
Country,
Title = Dropdown_Secondary.Selected.Title
),
Filter(
Country,
Continent = Dropdown_Primary.Selected.Result
)
)
)

If you just want to use a single Dropdown, or add a third, no problem!  Just adapt the above code and off you go!

References

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top