cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate IV
Advocate IV

SortByColumn: set default value and have it as "selected" for gallery

Is it possible to have the "selected" item "sticky" when using SortbyColumn? For example, I have itemA selected, then I sort the gallery by id. I am hoping to see itemA is still selected, or, at least the 1st item on the new list is selected. Right now, it seems to select a random value after sorting. Thanks. 

1.PNG

6 REPLIES 6
Highlighted
Super User III
Super User III

Re: SortByColumn: set default value and have it as "selected" for gallery

Hi @NewBee117 ,

The property to control the "sticky" item is TemplateFill for the gallery.

it is normally set to something like If(ThisItem.IsSelected,<Color>,White) meaning it shows the user the last item they selected when they come back to the gallery, which is often on a different screen.

Without seeing your code, it cannot give you a proper answer, but it should be possible if you can refer the other gallery

Lookup(ThisItem.<Identifier>= . . the other gallery.selected.<same id>

Give it a go - happy to help if you get stuck

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Advocate IV
Advocate IV

Re: SortByColumn: set default value and have it as "selected" for gallery

Thanks for writing back. There is only one gallery in this exercise. Here are my code. 

 

Code.PNG

And here is how the app works:

 Action.PNG

Stick should keep ItemA selected (blue) regardless which row it is on. Is it possible?

Highlighted
Super User III
Super User III

Re: SortByColumn: set default value and have it as "selected" for gallery

Ok @NewBee117 ,

I will get back to you on this - a fair bit of code to look through

Highlighted
Community Support
Community Support

Re: SortByColumn: set default value and have it as "selected" for gallery

Hi @NewBee117 ,

The reason why you met this problem is that:
Gallery.Selected will change to the first item by default.

So when you change the table's order, the selected item will change together.

However, I've figured out a solution to avoid the order's effect.

I suggest you save the table's data to collection and update the selected item to a certain value. Make the item that has the certain value as "selected item".

I've made a similar test for your reference:

I assume that your original table name is test.

1)save the original table as a collection 

set the screen's OnVisible:

ClearCollect(test1,AddColumns(test,"selected",false))

//add a column that save the certain value

2)update the collection, update the selected item with certain value (true)

set the arrow button inside the gallery's OnSelect:

ClearCollect(test1,AddColumns(test,"selected",false));Patch(test1,ThisItem,{selected:true})

set the gallery's Items:

SortByColumns(test1,"....",If(var1,Descending,Ascending))
//replace the field that you want

set the sort button's OnSelect:

Set(var1,!var1)

3)make the item has certain value as the selected one

For example: 

set the arrow button's Color:

If(ThisItem.selected,Red,Blue)

 

Then the selected item's arrow button will be red,others will be blue. And this will not change with the order's changing.

21014.PNG

 

21015.PNG

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Advocate IV
Advocate IV

Re: SortByColumn: set default value and have it as "selected" for gallery

I put in your code, and the visual effect looks like it is sticky to the arrow, however, it is not the true selected item after the sort, the item highlighted in blue (TemplateFill) is. Good try though.

 

ItemA moved to top row with the red arrow and the AddColumn of "selected", however, the third row is the true "selected" in blue.

 

      2.PNG

Highlighted
Super User III
Super User III

Re: SortByColumn: set default value and have it as "selected" for gallery

Hi @NewBee117 ,

I will drop out of this - looks like @v-yutliu-msft has got it completely under control

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

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

Top Solution Authors
Top Kudoed Authors
Users online (5,621)