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

Can't get the sort button and text search to work in my app

I have been trying unsuccessfully for a few days to get the sort button and seach bar here to work.  I have searched these forums and tried multiple solutions, but can't seem to get either to work.  My gallery screen is sorted and filtered by a date field named 'sikr'.

Ideally, I would like to be able to search for records by that date column as well as by a few other text columns.  As far as the sort button, I only want it to change the sort of the records by the sikr (date) field from ascending to descending and back. 

 

Thanks in advance for any help on this.

 

Here is a screen shot of the gallery screen and properties.

 

gallery.jpg

7 REPLIES 7
Skete211
Level: Powered On

Re: Can't get the sort button and text search to work in my app

I might add that the Filter function does give off a blue dot notification, but the function works.  Not sure if that has any effect on the issue of sort and search.  Sorry, I am not an experienced programmer.

Anonymous
Not applicable

Re: Can't get the sort button and text search to work in my app

@Skete211: No worries. PA is advertised as no-code, after all. Also, I don't have much experience with PA templates so what I suggest might not be right.

 

My suggestion is to do the following:

  • Use a context variable as a flag to determine if sorting is Ascending or Descending. For now, let's call it isSortDescending and initialize it to false.
  • Then, use Filter() to filter your data with the search terms. For now, we'll use the in operator just to check whether your search term is a part of the title. Reference: https://docs.microsoft.com/en-us/powerapps/functions/function-filter-lookup
  • Then, use Sort() to sort the results of the filter function. Use If() for the third parameter and use the context variable, isSortDescending, to control whether argument passed (whether it's SortOrder.Ascending or SortOrder.Descending). Reference: https://docs.microsoft.com/en-us/powerapps/functions/function-sort

What the code should look like:

  • OnVisible of the current screen:
    UpdateContext({ isSortDescending: false })
  • OnSelect of the filter button:
    UpdateContext({ isSortDescending: !isSortDescending })
    This basically toggles the value of isSortDescending. If it's true, set it to false. If it's false, set it to true.
  • Items of your gallery object.
    Sort(
        Filter( 
            'AV Log', 
            sikr > Today() - 60, 
            TextInput1.Value in Title
        ),
        sikr,
        If( isSortDescending, SortOrder.Descending, SortOrder.Ascending )
    )
    Assuming that the name of your text input (search bar) is TextInput1 and your top field (the ones that have the addresses) is called Title.
    Add more conditions as needed in the Filter() function. For more filter options, your Filter() is going to be more complicated.

Also ---

The blue notification icon basically says that the function cannot be delegated. For smaller data sizes (number of records is less than 500), this is not a problem. Functions that have this blue icon will still work but will ignore the 501th record and beyond. 

Refer to this page for more info: https://docs.microsoft.com/en-us/powerapps/delegation-overview. 

 

Let me know what you think.

Skete211
Level: Powered On

Re: Can't get the sort button and text search to work in my app

@Anonymous

 

Thank you for your response.  Unfortunately, I didn't work.  The two onselect properties went in without throwing off any errors, but the "Items" property did not work.  It gave me the blue warning, but then all of the data that was appearing, then stopped showing.  I tried to see if the search box would return and nothing happens.  I can't check the sort button as nothing displays to sort.  It's not erroring out, just not showing anything.

 

 

Anonymous
Not applicable

Re: Can't get the sort button and text search to work in my app

@Skete211 --

Again, the blue warning is just to say that the function is non-delegable. So, back to the main issue. I don't exactly know how you've configured things there but let's try to narrow down the problem.

 

First, can you change the Items code to this:

Sort(
    Filter( 
        'AV Log', 
        sikr > Today() - 60
    ),
    sikr,
    If( isSortDescending, SortOrder.Descending, SortOrder.Ascending )
)

What I did was remove the third argument for the Filter() function and thereby, removing the search functionality. You should be able to see all the records for now but the search bar won't work. 

 

Second: if you've added the first bit of code I gave you to the OnVisible property of the screen (I haven't read that you did in your post), then that code only executes when the screen becomes visible. So, for that to work, you may have to move to another screen while editing and going back to it. 

 

Let me know what changes.

Skete211
Level: Powered On

Re: Can't get the sort button and text search to work in my app

@Anonymous

 

Your change in code allowed for the sort button to start working and the gallery screen now sorts by date ascending  and descending.  Thank you for that.

 

So we eliminated the search capability out of that code to make it sort.  Can we add the search function back in somehow?  

 

I really appreciate all of your help.

Anonymous
Not applicable

Re: Can't get the sort button and text search to work in my app

@Skete211 --

Well, that narrowed down the problem. To be honest, I don't have much experience with making a search function in PA and code I've given you looks like it works. I just don't know why it doesn't. 

 

I'd help you with this further but I'm on break starting today until the 2nd of January. I won't have time to experiment with PA and find out what works until I'm back. I suggest you post another question in the community (hope someone's here for the holidays) or just look around if somebody had posted a solution for search. 

 

I did enjoy helping out. Thanks and welcome. Smiley Happy Happy holidays!

Skete211
Level: Powered On

Re: Can't get the sort button and text search to work in my app

Thank you for your help @Anonymous and I wish you a good holiday break!

 

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

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

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 225 members 4,710 guests
Recent signins:
Please welcome our newest community members: