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 III
Super User III

@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."

 

View solution in original post

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (27,025)