Row reordering with List buttons

Copper Contributor

Hello, I would like to setup a mechanism to allow rows in a SharePoint list to be re-order by the click of a button. 

I have a list that is sorted by a unique sequence number column (integers) displaying the smallest number first.

 

My idea is to add two buttons on every row, an up arrow and a down arrow.

When the up arrow is clicked, the sequence number of the row should be swapped with the row that is one less and visa versa if the down arrow is clicked. 

 

EX: If I click the up arrow on the item with sequence number 2, this item should now be sequence number 1, and sequence number 1 should become sequence number 2. 

CamCov_0-1702047925731.png

 

Hard for me to Believe that this is not a built-in function of SharePoint, but i cannot find this exact case. 

 

Any help is greatly appreciated!!

 

4 Replies

@CamCov it's not a built-in function because SharePoint has never been able to iterate over a couple of rows to update column values in the way you are suggesting. It CAN be done with JSON-formatted buttons that trigger flows in Power Automate. If I get a chance over the weekend I'll post up the solution.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP (and classic 1967 Morris Traveller driver)

@CamCov ok so I have a list as shown below which has a single line of text column for each of the SwapSequence columns. I'll give you the JSON for that later in this post as you need to create the 2 flows first, 1 to move the selected item up 1 in the sequence and 1 to move it down and swap the other item affected.

0-SP-Up.png

 

The Swap Sequence + button triggers the following flow:

The trigger is for a selected item, then the first action is to get the item. Then add a compose and select Sequence from the dynamic content box. Then add another compose to add 1 to the sequence number.

 

1-Flow-Up.png

 

We then get the item that currently has a sequence number of seq+1 and we add a compose to take 1 away from it:

 

2-Flow-Up.png

 

Next, add an apply to each and inside it add an update item action that updates the previous +1 item with a new sequence number that is 1 less.

 

3-Flow-Up.png

 

Then outside the apply to each update the item you selected by adding 1 to it:

 

4-Flow-Up.png

 

 

Once you've built this flow you need to add a new single line of text column to your SharePoint list and format it in advanced mode with the following JSON, changing the id in the actionParams line to the id of your flow:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Swap Sequence +",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "='{\"id\":\"cdb95289-8680-4fca-97b0-21d4645be08d\", \"headerText\":\" ' + [$Title] + '\",\"runFlowButtonText\":\"Go\"}'"
  },
  "style": {
    "background-color": "#b2eee6",
    "border-radius": "10px"
  }
}

 

So in running the flow we're going to click the Guadaloupe swap sequence + button which will swap it with the Cayman Islands. This is the result:

 

5-SP-Up-REsult.png

 

For the swap sequence down flow you need to save the flow you've just built as a copy, rename it and then go through it to do the opposite of what you did before.

 

Then add another single line of text column to your list and paste in the JSON but with the id of the new flow.

 

Come back with any questions about this.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP (and classic 1967 Morris Traveller driver)

 

@Rob_Elliott 

Hi Rob, thank you so much for your time and effort to help me create this solution for my users.

I have implemented your suggestion as you described, and it works!

 

This solution would be perfect if the pop-out pane to confirm the starting of the flow could be disabled or auto confirmed in some way. Any ideas there, or am I stuck with that?

 

I also found another solution that allows me to change the sequence number entirely through column formatting, but unfortunately it will not let me enforce unique numbers as it does not perform a swap. I am thinking that if I create some sort of linked list where ID's are held by adjacent items, I could maybe create a swap sequence mechanism using the row action "SetValue", but I have been unable to find documentation around changing another row's value. Does this spark any ideas for you?

 

I attached a screenshot of what I mean. I figure I should be able to set the value of a column in any row if I already have the ID of that row stored in the column where the button is clicked.  

 

Again, your help to this point is greatly appreciated!!!

 

@CamCov "This solution would be perfect if the pop-out pane to confirm the starting of the flow could be disabled or auto confirmed in some way." That is not possible.

 

"I could maybe create a swap sequence mechanism using the row action "SetValue", but I have been unable to find documentation around changing another row's value."  I don't know of any way to get the setValue to change a different row's value.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP (and classic 1967 Morris Traveller driver)