cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JimmyWork
Level 8

Filter gallery on Current user and Text input field

Hi 

 

Im having trouble sorting out a filter need on a gallery in powerapps.

I would like to display only items created by the user. To do this i do the following.

Gallery item: Filter('ListName', Author.Email=CurrentUser)

The above works fine.

 

Now i have a Text input where i would like users to search the items they have created.

I can do that with the following.

SortByColumns(Filter('ListName', StartsWith(Title, TextInput.Text)), "Title")

The above sorts all items.

 

How can i combine both?

I want the user to only see the items they have created and i want them to be able to use the text box to search there items using the title.

 

 

6 REPLIES 6
Eelman
Level 10

Re: Filter gallery on Current user and Text input field

Assuming the users only ever see their own items, you could create a collection in either App.OnStart or screen OnVisible that filters the data source 'ListName' for the users items. Then use this collection for the Items of your gallery.

 

Eg.

App.OnStart = ClearCollect( colUserItems, Filter('ListName', Author.Email=CurrentUser) )

Gallery.Items = colUserItems

Highlighted
JimmyWork
Level 8

Re: Filter gallery on Current user and Text input field

Looks like i can use the following.
Filter('ListName', Author.Email=CurrentUser || SearchCourses.Text in Title)

 

I do get a delegation warning so i wonder if there is a better way to do this?

JimmyWork
Level 8

Re: Filter gallery on Current user and Text input field

@Eelman Thank you for answering.

Im trying to have a searchbox that can search the gallery to and display only current users items. If search is empty ti shows the user a list of all there items then they can use search to to find more specific items in there own list

Eelman
Level 10

Re: Filter gallery on Current user and Text input field

@JimmyWork if this code works use it. You can mostly ignore the delegation warnings if your data sources are pretty small (<2000 records)

Super User
Super User

Re: Filter gallery on Current user and Text input field

You’ve done all the hard work. All we have to do is combine your functions and do a little magic with IF + ISBLANK. This might solve your delegation issue too.

SortByColumns(Filter('ListName',Author.Email=CurrentUser,If(IsBlank(TextInput.Text),true,StartsWith(Title, TextInput.Text))),"Title")

—-
Please Accept as Solution if this post answered your question so others may find it more quickly. If you found this post helpful consider giving it a Thumbs Up.
Community Support Team
Community Support Team

Re: Filter gallery on Current user and Text input field

Hi @JimmyWork ,

Do you want to combine the two filter condition that you mentioned?

 

Currently, the 'in' operator could not be delegated within SP connector, please check the following article:

https://docs.microsoft.com/en-us/connectors/sharepointonline/#powerapps-delegable-functions-and-oper...

 

Please consider modify your formula as below:

SortByColumns(
               Filter(
                      'ListName',
                       Author.Email = CurrentUser,
                       StartsWith(Title, TextInput.Text)
               ), 
               "Title"
)

Note: I assume that the CurrentUser store the email address of the current login user.

or

SortByColumns(
               Filter(
                      'ListName',
                       Author.Email = CurrentUser,
                       If(
                          IsBlank(TextSearchBox1.Text),
                          true,
                          StartsWith(Title, TextInput.Text)
                       )
               ), 
               "Title"
)

 

If the amount of your SP List records is not more than 2000, you could ignore the Delegation warning issue within your formula (using 'in' operator). If the amount of your SP List records is more than 2000, you could consider bulk-load your SP list records into your app as Collection. Then use the collection as data source in your app.

Please check and see if the alternative solution I mentioned below could help in your scenario:

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Sort-gallery-with-multiple-fields/t...

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,070)