cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aharsh
Helper II
Helper II

Creating a Search/Filter outside the initial view of Gallery

Hi All,

 

I have figured out how to do the things I need to do, I just can't do them on the same screen using the same Gallery!  

 

When the user first lands on the page, I want them to see the gallery filtered and sorted like this (moderated=1 is important, only approved items should show in the gallery):

 

Sort(Filter('GalleryName', moderated = "1"),date,Descending)

 

Now, I want to let them search by last name.  This works, kinda - it should should still be moderated="1", my search box lets you search everything - even moderated = 0:

 

 Search('GalleryName', SearchBox.Text,"nLName")

 

To be even more complex, I also want them to filter by a choice column in my list (search employees by their specific directorate - 4 total).  I was thinking of adding 4 buttons and each button refreshes the gallery with this code.  I'm not sure how to link the button to refresh the list, I tried putting this code into the OnSelect of the button, but it didn't do anything, of course!

 

Filter('HCSO Kudos Employees', nDirectorate.Value = "AQD",moderated="1") 

 

I'm open to ideas of how to make this more simple.

 

Thank you!!!

1 ACCEPTED SOLUTION

Accepted Solutions

@aharsh 

To this I would suggest creating a collection by putting this code in the OnVisible property of the screen

 

ClearCollect(colDropdownOptions, ["All"]);
Collect(colDropdownOptions, Choices('HCSO Kudos Employees'.nDirectorate));

 

Use the collection to build the dropdown by putting it in the Items property of the dropdown

 

colDropdownOptions

 

This dropdown will have an "All" option at the top

Value
All
Choice1
Choice2
Choice3

 

Finally, build this additional condition into the Items property of your gallery.

 

Search(
    Sort(
        Filter(
            'HCSO Kudos Employees',
            Dropdown_nDirectorate.Selected.Value = "All" Or
            nDirectorate.Value = Dropdown_nDirectorate.Selected.Value,
            moderated = "1"),
        date, Descending),
    SearchBox_1.Text, "nLName"
)

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

View solution in original post

7 REPLIES 7
mdevaney
Super User
Super User

@aharsh 

My first suggestion is: use a single drop-down instead of buttons to let the user select nDirectorate.  Put this code in the Items property of the drop-down to populate it with the Choices values.

 

Choices(your_datasource_name.nDirectorate)

 

Assuming the rest of your code already works just incorporate the dropdown as shown below.

Search(
    Filter(
        'HCSO Kudos Employees',
        nDirectorate.Value = Dropdown_nDirectorate.Selected.Valueq,
        moderated="1"
    ),
    SearchBox.Text, "nLName"
) 

 

You'll get a delegation warning due to using the SEARCH function.  If you need to search past 2,000 rows the only workaround is to use STARTSWITH instead.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Hi @mdevaney ,

 

Thank you so much, I got it working using your recommendation.

 

How would I clear the search?  When I used the dropdown it makes the dropdown search active and the search by last name doesn't work and I can't find how to clear the dropdown search to get back to the initial view.

 

Thanks!

Hi @mdevaney 

 

I also realized your solution strips out the ",date,Descending" from the initial view.  I've tried multiple ways to add that back but it doesn't play nice with "search by last name" 

I'm so sorry, I'm being so obnoxious with so many messages!! @mdevaney 

 

I have figured out how to both get the dropdown and LastName to work at the same time. As well as have the initial view start with date descending. 

 

I'm still stuck on how to cancel the dropdown once it's activated. 

 

Here is my current code:

 

Search( Sort(Filter('HCSO Kudos Employees',nDirectorate.Value = Dropdown_nDirectorate.Selected.Value, moderated = "1"),date,Descending), SearchBox_1.Text, "nLName" ) 

 

And in my dropdown

 

Choices('HCSO Kudos Employees'.nDirectorate)

 

I've been trying to figure out some type of "clearall" function, maybe?

 

THank you!

@aharsh 

To this I would suggest creating a collection by putting this code in the OnVisible property of the screen

 

ClearCollect(colDropdownOptions, ["All"]);
Collect(colDropdownOptions, Choices('HCSO Kudos Employees'.nDirectorate));

 

Use the collection to build the dropdown by putting it in the Items property of the dropdown

 

colDropdownOptions

 

This dropdown will have an "All" option at the top

Value
All
Choice1
Choice2
Choice3

 

Finally, build this additional condition into the Items property of your gallery.

 

Search(
    Sort(
        Filter(
            'HCSO Kudos Employees',
            Dropdown_nDirectorate.Selected.Value = "All" Or
            nDirectorate.Value = Dropdown_nDirectorate.Selected.Value,
            moderated = "1"),
        date, Descending),
    SearchBox_1.Text, "nLName"
)

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

Hi @mdevaney  - You are a genius!

 

I've been banging my head all morning trying to figure out how to wrap it in a collection, and you make it look so easy.

 

This works perfectly.

 

THANK YOU!!

@aharsh 

It was a pleasure to help you: I like helping others solve their PowerApps issues 🙂 

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,711)