web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter a gallery on bu...
Power Apps
Unanswered

Filter a gallery on button click

(0) ShareShare
ReportReport
Posted on by 42

Hi,

 

I am new to Power apps, and am creating a Canvas app. I have a gallery that I want to filter based on the content of a Text Input field, but only when someone clicks a button. This button is also responsible for showing a loading spinner whilst the gallery is filtered. 

 

The button's OnSelect property is 

Set(varIsLoading, true);

 

My Gallery's Items is currently:

 

If(varIsLoading = false,FirstN('SalesLT.Customer', 100), Filter('SalesLT.Customer',
        StartsWith(FirstName, Trim(First(Split(TextInput1.Text, " ")).Value)) &&
        StartsWith(LastName, Trim(Last(Split(TextInput1.Text, " ")).Value))
    ))

 

But, I want it so that the gallery is filtered only when the button is clicked (using the same functionality in my Filter in gallery items), and that the spinner (which has a visible property of varIsLoading) appears only when the data is being obtained, and goes away when the gallery has finished loading.

 

Any help would be much appreciated for a newbie. Currently, the filter works itself, but it starts to filter as soon as someone types in the text input field, but I want it to be on button click to show the spinner etc. 

 

Thanks

LM.

 

Categories:
  • cwebb365 Profile Picture
    3,334 Most Valuable Professional on at

    Change out your TextInput1.Text with varTextInput1 and then on your button UpdateContext({varTextInput1:TextInput1.Text})  to set that field. Then whenever you want to undo you do UpdateContext({varTextInput1:""})  This should work. 

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @LostMary,

     

    Below I have made some code adjustments. In this specific case I don't think you need a loading spinner since the data loading should occur very quickly.

    Button's OnSelect

    UpdateContext({varFilter: TextInput1.Text})
    
    //To reset via e.g. another button or cancel icon use UpdateContext({varFilter: Blank()})

     
    Gallery's items property

    If(
     IsBlank(varFilter),
     FirstN(
     'SalesLT.Customer', 
     100
     ), 
     With(
     {wFilterTrim: Trim(varFilter)},
     Filter(
     'SalesLT.Customer',
     StartsWith(FirstName, Left(wFilterTrim, Find(" ", wFilterTrim) - 1)),
     StartsWith(LastName, Right(wFilterTrim, Find(" ", wFilterTrim) - 1))
     )
     )
    )

     

    Should a loading spinner be a requirement you may want to use a collection and recollect when using the button filter - here you can clearly indicate the start and end loading time.

    //OnVisible of the Screen
    ClearCollect(colSalesLT, FirstN('SalesLT.Customer', 100))
    
    //Items property of gallery
    colSalesLT
    
    //Button OnSelect
    UpdateContext({varLoading: true});
    ClearCollect(
     colSalesLT,
     With(
     {wFilterTrim: Trim(varFilter)},
     Filter(
     'SalesLT.Customer',
     StartsWith(FirstName, Left(wFilterTrim, Find(" ", wFilterTrim) - 1)),
     StartsWith(LastName, Right(wFilterTrim, Find(" ", wFilterTrim) - 1))
     )
     )
    );
    UpdateContext({varLoading: false});
    
    //Loading spinner Visible property
    varLoading

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • LostMary Profile Picture
    42 on at

    Thanks for your reply. The loading spinner is an explicit requirement sadly.

     

    In the code for the OnSelect of the button, I get the below?

     

    Trim(varFilter)     -varFilter isn't recognised.
    A delegation warning under the first StartsWith
     
    Any help would be much appreciated
     
    LM.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 223

Last 30 days Overall leaderboard