cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
NewBee117
Advocate V
Advocate V

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
WarrenBelz
Super User
Super User

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.

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?

WarrenBelz
Super User
Super User

Ok @NewBee117 ,

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

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.

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

WarrenBelz
Super User
Super User

Hi @NewBee117 ,

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,367)