cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
daleritf
Level: Powered On

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
PowerApps Staff CarlosFigueira
PowerApps Staff

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')
daleritf
Level: Powered On

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.

 

PowerApps Staff CarlosFigueira
PowerApps Staff

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 })
daleritf
Level: Powered On

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

PowerApps Staff CarlosFigueira
PowerApps Staff

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")
daleritf
Level: Powered On

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.

daleritf
Level: Powered On

Re: Filter onSelect

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

 

Thank you

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Filter onSelect

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

daleritf
Level: Powered On

Re: Filter onSelect

Please let me know if you have any results of tests

Thanks

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 59 members 4,892 guests
Please welcome our newest community members: