cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BCBuizer
Resolver III
Resolver III

Gallery sorting not working

Hi All,

 

I'm creating a gallery in which items can be sorted by the user using two arrow icons to move them up or down:

BCBuizer_0-1634673097135.png

Pressing the icons updates a column called 'Sorting order', for instance:

 

OnSelect= Set(varSort,ThisItem.SortOrder);
Patch(collection,LookUp(collection,SortOrder=Text(Value(varSort+1))),{SortOrder:varSort});
Patch(collection,LookUp(collection,ID=ThisItem.ID),{SortOrder:Value(varSort)+1})

 

In turn, the gallery is sorted, based on the value of the Sort Order column:

 

Items = 
Sort(
    Filter(
        collection,
        IsBlank(LinkedDocument)
    ),
    "SortOrder",
    Descending
)

 

As you can see in the above picture, initially this gives the correct order (the number is ThisItem.'Sort Order'). When clicking on either of the item, the values of the Sort Order change correctly, yet the order of the items in the gallery doesn't (clicked 'Up' on the bottom, red item):

BCBuizer_1-1634673595963.png

Can anybody give an idea of what should do to get the order of the item in the gallery to what it should be? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@BCBuizer 

Your sort order should be numeric.

Your formula for the down arrow:

With({_current: LookUp(collection, 'Sort Order'=ThisItem.'Sort Order' +1)},

    UpdateIf(collection, 'Sort Order'=ThisItem.'Sort Order', {'Sort Order': ThisItem.'Sort Order'+1});
    Update(collection, _current, Patch(_current, {'Sort Order': ThisItem.'Sort Order'}));
)

...is correct - except you should not be using the Value function on Sort Order. 

This above should be giving you what you need.

 

If not, try to invoke the down button and then take a look at your collection to see what values it has for the two rows in question.

 

Also, just to be sure, your Items property on the Gallery should be:

Sort(
    Filter(
        collection,
        IsBlank(LinkedDocument)
    ),
    'Sort Order'
)

NOTE: This is an alteration of your original Items property as it was not correct.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@BCBuizer 

 

The trick is changing the proper records in your table and realizing that once you change one, then logic for the next on is missing.

 

Easier to demonstrate than to explain.

 

Please see the attached app.  Download it and save it.  Then in PowerApps, edit an existing app or create a new app, then then go to File -> Open   Then Browse for the file you downloaded.

 

It is a full operational re-ordering gallery.  The only formulas in it are on the OnSelect of the up and down arrows.  The data used is created in the OnCheck action of Toggle1 in it.  Nothing else going on.

 

Take a look and see if it is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hello Randy,

 

Thanks for the reply. I see your point, but I though I had addressed that.

 

When running your app the sorting works, but when I adapted the code for the arrows to my app, the result was the same.

 

OnSelect= 
With({_current: LookUp(collection, Value('Sort Order')=ThisItem.'Sort Order' +1)},

    UpdateIf(collection, 'Sort Order'=ThisItem.'Sort Order', {'Sort Order': ThisItem.'Sort Order'+1});
    Update(collection, _current, Patch(_current, {'Sort Order': ThisItem.'Sort Order'}));
)

 

BCBuizer_0-1634677039734.png

 

Could the issue be in the fact that 'Sort Order' is a text type column?

*Edit: I just changed the column type to number and it doesn't make a difference.

RandyHayes
Super User
Super User

@BCBuizer 

Your sort order should be numeric.

Your formula for the down arrow:

With({_current: LookUp(collection, 'Sort Order'=ThisItem.'Sort Order' +1)},

    UpdateIf(collection, 'Sort Order'=ThisItem.'Sort Order', {'Sort Order': ThisItem.'Sort Order'+1});
    Update(collection, _current, Patch(_current, {'Sort Order': ThisItem.'Sort Order'}));
)

...is correct - except you should not be using the Value function on Sort Order. 

This above should be giving you what you need.

 

If not, try to invoke the down button and then take a look at your collection to see what values it has for the two rows in question.

 

Also, just to be sure, your Items property on the Gallery should be:

Sort(
    Filter(
        collection,
        IsBlank(LinkedDocument)
    ),
    'Sort Order'
)

NOTE: This is an alteration of your original Items property as it was not correct.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Thanks Randy!

 

Turns out I was sorting by "SortOrder" instead of 'Sort Order'.... Thanks for pointing that out!

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,178)