Auto Numbering Sorting with Previous Row

Ohhh, mine was only Pro Team…

Hi Biha,

I misunderstood one of your posts, I only just understood now that you didn’t simply want to number your collection but that you also wanted a way to sort it. Indeed the RowIndex technique will give us dynamic row indexing/numbering, but nothing else.

Based on Thin’s recommendation, here’s how I would do it. I’ll put screenshots.

In a nutshell, the idea is to setup two buttons via a button block component, and when a button is clicked, two sort indexes are swapped (they take the place of one another) via Set Column Values custom actions. To be honest, to me this thing is a brain twister, it creates knots in my brain, like driving on the other side of the road with my arms crossed.

Layout Editor

  • Collection with a button block and arrows on each item to move them up and down.
  • Up button on the 1st item and down button on the last item are hidden via conditions by using RowIndexMax and 0. It would be a tad more rigorous to use RowIndexMin instead of 0, but it’s close enough.

Data Editor

  • RowIndexMax. RowIndex is only used to determine RowIndexMax via a rollup count.
  • Sorting. The manual sorting feature really only needs 3 columns: SortIndex which is the main sorting column, and then the index of the previous and next item respectively with +1 and -1 in two computed math columns.
  • Relations. You’ll need relations to the next and previous items to write to their rows. If this is not straightforward, do ask of course.

Action Editor

Here is the brain twister, for me.

This was for one of the buttons. Apply the same principle to the other button.

Layout Editor

Back in the layout, bind the sort order of the collection to the SortIndex column.

Adding and remove rows

  • Add. When adding a row, make sure the SortIndex for this new row is RowIndexMax+1.
  • Remove. The sorting indexes are going to get messed up here. So either my approach hit a limitation here, or there’s a way to clean up the sorting indexes so they remain consecutive. I’m not sure.
1 Like

:astonished: :astonished: Perfecttttttttt

1 Like

Well, it’s a solution. A solution that stops short of how to remove an item from the collection and yet not break the sorting feature.

Two ideas that I haven’t explored to address the limitation:

  1. When a row other than the highest index is removed, adjust all the rows with a higher index than itself by lowering their index by 1. I wouldn’t be too excited about implementing this.

  2. I think the whole limitation comes from identifying the next and previous items via math columns and their indexes. Identifying the next and previous items independent of their indexes would be more powerful and elegant. I think this could be achieved with arrays, sort array, and slice array. By leveraging the RowIndex column, that one again. But you’d have to implement this to test, this is just an idea.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.