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

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

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

Hi @NewBee117 ,

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

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (67,071)