cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

gallery sort buttons

Hello All,

 

I have an app being used to present project status for execs.  Data is fed from sharepoint.  They would like the ability to re-order the gallery easily without going into each individual record.  Looking to see if anyone has done anything like the following where the down arrows will cause the gallery item to switch with the one below and other way around with the up arrow.  

 

PA - Example.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Was thinking of just have a sort field in sharepoint and having the gallery buttons increment/decrement that field value, but couldn't think through how to have the gallery item above or below adjust as well.

 

Thanks,

 

Eko

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
bdodu
Level 8

Re: gallery sort buttons

I gave you a kudo for your question. I liked it.

 

I managed to solved it, hope you like the solution. It seems it should be addressed by sorting differently the data source. However to my knowledge there is neither RowNumber function nor posibility to iterate through a collection.

 

Therefore we need a trick to obtain a sort order and my proposal is to build a collection from the data source and add a column called SortIndex with a 0 default value.

 

OnVisible = ClearCollect (workingDS, AddColumns('your-data-source',"SortIndex", 0) );

Map the gallery Items property to the workingDS. 

 

Sort( workingDS,SortIndex, Ascending)

Now the gallery looks like this:

 

image.png

 

Now let's add a Timer on the form with the following properties:

 

Repeat = If(CountRows(Filter(workingDS,SortIndex=0))=0, false,true )
Autostart = true
Duration = 10; if ( false," Please adjust according to your needs")
OnTimerStart = Patch(workingDS,First(Filter(workingDS,SortIndex=0)),{SortIndex : currentIndex})
OnTimerEnd = UpdateContext({currentIndex: currentIndex +1})
Visible = false

 The result is:

 

image.png

 

 

Now on an event to reorder (UP), just change the value of the ThisItem.SortIndex with  ThisItem.SortIndex-1 and Patch the collection to increase the SortIndex column value with 1 for the record with Sortindex = SortIndex -1 like this (on the reorder button OnSelect property):

 

 

OnSelect = Patch(workingDS, First(Filter(workingDS, SortIndex = ThisItem.SortIndex)), 
{SortIndex: -1 });
Patch(workingDS, First(Filter(workingDS, SortIndex = ThisItem.SortIndex -1)),
{SortIndex : ThisItem.SortIndex});
Patch(workingDS, First(Filter(workingDS, SortIndex = -1)),
{SortIndex: ThisItem.SortIndex-1 })

 

 The result after I pressed the button on the second line:

 

image.png

 

Now a similar approach to be taken for the DOWN button, carefull to disable first row UP button and last row DOWN button. 

3 REPLIES 3
Highlighted
bdodu
Level 8

Re: gallery sort buttons

I gave you a kudo for your question. I liked it.

 

I managed to solved it, hope you like the solution. It seems it should be addressed by sorting differently the data source. However to my knowledge there is neither RowNumber function nor posibility to iterate through a collection.

 

Therefore we need a trick to obtain a sort order and my proposal is to build a collection from the data source and add a column called SortIndex with a 0 default value.

 

OnVisible = ClearCollect (workingDS, AddColumns('your-data-source',"SortIndex", 0) );

Map the gallery Items property to the workingDS. 

 

Sort( workingDS,SortIndex, Ascending)

Now the gallery looks like this:

 

image.png

 

Now let's add a Timer on the form with the following properties:

 

Repeat = If(CountRows(Filter(workingDS,SortIndex=0))=0, false,true )
Autostart = true
Duration = 10; if ( false," Please adjust according to your needs")
OnTimerStart = Patch(workingDS,First(Filter(workingDS,SortIndex=0)),{SortIndex : currentIndex})
OnTimerEnd = UpdateContext({currentIndex: currentIndex +1})
Visible = false

 The result is:

 

image.png

 

 

Now on an event to reorder (UP), just change the value of the ThisItem.SortIndex with  ThisItem.SortIndex-1 and Patch the collection to increase the SortIndex column value with 1 for the record with Sortindex = SortIndex -1 like this (on the reorder button OnSelect property):

 

 

OnSelect = Patch(workingDS, First(Filter(workingDS, SortIndex = ThisItem.SortIndex)), 
{SortIndex: -1 });
Patch(workingDS, First(Filter(workingDS, SortIndex = ThisItem.SortIndex -1)),
{SortIndex : ThisItem.SortIndex});
Patch(workingDS, First(Filter(workingDS, SortIndex = -1)),
{SortIndex: ThisItem.SortIndex-1 })

 

 The result after I pressed the button on the second line:

 

image.png

 

Now a similar approach to be taken for the DOWN button, carefull to disable first row UP button and last row DOWN button. 

Anonymous
Not applicable

Re: gallery sort buttons

Thanks bdodu!

 

I ended up taking pieces of what you suggested and am using the following:

 

Up Arrow OnSelect:

Patch('Project Execution View',First(Filter('Project Execution View',Review_x0020_Order = ThisItem.Review_x0020_Order-1)),{Review_x0020_Order: ThisItem.Review_x0020_Order});
Patch('Project Execution View',ThisItem,{Review_x0020_Order: Review_x0020_Order - 1})

Up Arrow Visibility

If(ThisItem.Review_x0020_Order = 1,false,true)

 

Down Arrow OnSelect:

Patch('Project Execution View',First(Filter('Project Execution View',Review_x0020_Order = ThisItem.Review_x0020_Order+1)),{Review_x0020_Order: ThisItem.Review_x0020_Order});
Patch('Project Execution View',ThisItem,{Review_x0020_Order: Review_x0020_Order + 1})

 

For the down arrow visibility, I'm still trying to determine options as max() can't be used remotely on a datasource.  The only challenge I'm running it with this method is that the patch time is fairly slow, so overall performance may be a concern.

 

I also reviewed and it look like by creating the collection, you are able to use countrows() and probably max() as well since the datasource isn't a remote connection.  Question that I have there -- within the app, do those collections persist.  IE ... If I update the order, will anyone else who views the app also see that order?

 

Thanks,

 

Eko

 

 

bdodu
Level 8

Re: gallery sort buttons

That's exactly he reason for using a collection in my answer:
1 - you can do more things within a collection
2 - it's runtime data for each user (collection is created for each user running the app)
3 - fast enough
4 - save back to datasource only what you need

 

So the answer is no, your users will have each their own sorting. you could use the collection to gain speed and on a specific event according to your needs to update the database (ie pressing the save changes button) - and then refresh the collection. this way of course the information becomes persistent for all users