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

Filter onSelect

Hi I am trying to filter data of My SharePoint List by clicking on the button.

 

SharePoint List Name: Group Project Tasks

Fields : Person Field named Assigned To

 

On the screen I set up a button which should filter and show Items in the list where curent User is assigned.

 

This is what I wrote onSelect for my button:

Filter('Group Project Tasks',Assigned_x0020_to.DisplayName=User().FullName)

 

Unfortunatelly nothing happens on the screen onSelect.

13 REPLIES 13
Highlighted
Power Apps
Power Apps

Re: Filter onSelect

The Filter function will not change the data source you pass in its first argument; instead, it will return a new collection, based on that data source, filtered by the condition you specify.

 

What you need to do is to use the filter expression in the Items property of the control (a gallery, I assume) that displays the tasks. If you always want the list to be filtered by the current user, you can use this expression in the Items property:

Filter('Group Project Tasks', Assigned_x0020_to.DisplayName = User().FirstName)

Alternatively, if you want a button to toggle between all items and your items, you can use a context variable and change its value in the button's OnSelect handler:

Button1.OnSelect: UpdateContext({ myTasksOnly: !myTasksOnly })
Gallery1.Items: If(myTasksOnly, Filter('Group Project Tasks', Assigned_x0020_to.DisplayName = User().FirstName), 'Group Project Tasks')
Highlighted
Helper II
Helper II

Re: Filter onSelect

It works as expected but it looks like same button does both operations show all and showMy in different clicks

I would like to have two seperate buttons:

Button 1.Onselect to show All Items and Button2.Onselect to show My only.

 

Please explain how can I achive this.

 

Highlighted
Power Apps
Power Apps

Re: Filter onSelect

In this case you can set the value of the variable to true or false in each of the buttons:

Button1.Text: "Show All Items"
Button1.OnSelect: UpdateContext({ myTasksOnly: false })

Button2.Text: "Show My Items Only"
Button2.OnSelect: UpdateContext({ myTasksOnly: true })
Highlighted
Helper II
Helper II

Re: Filter onSelect

Is there any changes in the Gallery1.Item ?

 

Currently I have this :

Search(Filter('Group Project Tasks', (ParentID=BrowseGallery1.Selected.ID)) , ActionSearch.Text, "Title")

 

Which allows me to search also.

 

Please let me know.

 

Sorry if I am asking dummy questions, I am just new at iy

Highlighted
Power Apps
Power Apps

Re: Filter onSelect

You could use the If function to have a conditional expression in the Gallery1.Items property:

If(
    myTasksOnly,
    Search(Filter('Group Project Tasks', ParentID = BrowseGallery1.Selected.ID, Assigned_x0020_to.DisplayName = User().FirstName), ActionSearch.Text, "Title"))
    Search(Filter('Group Project Tasks', ParentID = BrowseGallery1.Selected.ID), ActionSearch.Text, "Title"))

If the variable is set to true, then you'd add another parameter to the Filter function; otherwise you can use the expression that you currently have.

 

You can also rewrite the expression above as shown below if you don't want to repeat yourself. Basically this is moving the 'if condition' to inside the search:

Search(
    Filter(
        'Group Project Tasks',
        ParentID = BrowseGallery1.Selected.ID,
        If(myTasksOnly, Assigned_x0020_to.DisplayName = User().FirstName, true)),
    ActionSearch.Text,
    "Title")
Highlighted
Helper II
Helper II

Re: Filter onSelect

I used second version and for some reason I am not getting any results back just blank screen. Any ideas why? I checked the spelling, everything looks ok.

Highlighted
Helper II
Helper II

Re: Filter onSelect

Please let me know if you have an idea why I am not getting result?

 

Thank you

Highlighted
Power Apps
Power Apps

Re: Filter onSelect

Not really (will try a few other options here); if you use the first option, does it work?

Highlighted
Helper II
Helper II

Re: Filter onSelect

Please let me know if you have any results of tests

Thanks

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (7,204)