# Auto Numbering Sorting with Previous Row

**URL:** https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026
**Category:** Ask for Help
**Created:** [September 12, 2023, 6:29am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026 "2023-09-12T06:29:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 12, 2023, 6:29am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/1 "2023-09-12T06:29:34Z")

</div>

Hi,  
i understand to use increment to make auto numbering.

1. Quotation
2. Part Requisition
3. Service
4. Invoice
5. Payment

But let say we deleted number 3. how to make other number affect too? Let say, this case,

1. Quotation
2. Part Requisition  
(deleted)
3. Invoice
4. Payment

---

<div class="post-metadata">

### Author: ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)
#### Post date: [September 12, 2023, 6:46am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/2 "2023-09-12T06:46:56Z")

</div>

There is a technique based on the usage of a Row ID column. Conceptually, since Row IDs are automatically added or deleted when a row is added or removed, this technique allows dynamic row indexing (or row numbering).

- Add a basic Row ID column.
- Add a basic lookup column that points to the Row ID column. You will get a column where each cell represents an array of all the Row IDs.
- Add a computed Find Element Index. Point the first field to the lookup column (the arrays), the second field to the Row ID column (the element whose index you are finding), adjust the display of the number to 1 (no digits after the comma) and no units.

Now you should have a column of numbers starting at 0 and automatically incrementing by 1 on each new row.

Should you want the row numbering to start at 1 instead of 0, add a computed math column and add 1 (+1) to the index column.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 12, 2023, 6:57am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/3 "2023-09-12T06:57:35Z")

</div>

I got it!  
But it is possible to do sorting ? Let say,

In in-line,  
i plan to add one button to move up one level.

Let say,

1. Quotation
2. Part Requisition
3. Service
4. Invoice (click once)
5. Payment

then it will be:

1. Quotation
2. Part Requisition
3. Invoice (click one more time)
4. Service
5. Payment

It become:

1. Quotation
2. Invoice
3. Part Requisition
4. Service
5. Payment

---

<div class="post-metadata">

### Author: ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)
#### Post date: [September 12, 2023, 7:08am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/4 "2023-09-12T07:08:28Z")

</div>

Yes, the technique I explained works fine with the sorting you showed.

There are a few places you can sort:

- In the Data Editor, in a Query column
- In the Data Editor, with a Sort Array column
- In the Layout Editor, in the options panel (right side) of a collection component.

I think sorting in the Layout Editor would be a sound approach.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 12, 2023, 7:43am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/5 "2023-09-12T07:43:29Z")

</div>

> [@nathanaelb](#):
>
> - In the Layout Editor, in the options panel (right side) of a collection component.
> 
> I think sorting in the Layout Editor would be a sound approach.

You mean this one ?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/7/37fa2ff641fe1830219f0b09388272ec06a6a5a4.png)

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 12, 2023, 8:23am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/6 "2023-09-12T08:23:01Z")

</div>

I want to ask you, meaning i need another one more column basically for sorting purpose right?

---

<div class="post-metadata">

### Author: ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)
#### Post date: [September 12, 2023, 11:06am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/7 "2023-09-12T11:06:36Z")

</div>

Yes, that is the place in the Layout Editor where you can sort a collection. In that area, you can define what attribute (column) you wish to sort along and then adjust the sorting options accordingly.

For instance, the table of a collection could have Row Index, Name and Date of Birth columns. You could sort along the Row Index column (which would be the same as sheet order), or Name, or Date of Birth. Same collection, different sorting result depending on the sorting attribute.

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 12:47am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/8 "2023-09-13T00:47:26Z")

</div>

The sorting part isn’t easily achieved. Nathanael’s method helps you add an index column, but that is a computed column and can’t be incremented or decremented.

If you can add a number column and add an index number every time you create a new record, then you increment/decrement and sort by that column when you move up or down the scales.

You must make sure that you also increment/decrement the items surrounding the items you are moving up or down to make it work.

Say you move Invoice from 4 to 3, then Service must be moved from 3 to 4 as a result.

In the end, it will likely be a combination of queries to get the “previous” and “next” row, then incremental actions.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 12:57am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/9 "2023-09-13T00:57:42Z")

</div>

Meaning, Nathan’s method is only for numbering right ?  
The sorting part is different part.

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 12:58am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/10 "2023-09-13T00:58:20Z")

</div>

Yes, I would say so.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 12:59am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/11 "2023-09-13T00:59:20Z")

</div>

Have you ever did before ? Hehe…

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 1:02am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/12 "2023-09-13T01:02:58Z")

</div>

No, I don’t have a use case for this. Please try to do it yourself based on the idea above and let us know if you get somewhere.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 1:05am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/13 "2023-09-13T01:05:43Z")

</div>

Ok Thinh, thank youuuu

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 5:25am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/14 "2023-09-13T05:25:24Z")

</div>

@ThinhDinh ,

I just found this thread. I managed to do what i need, based on your idea. Hehehehheheehe, thank you.

What did you eat everyday eh? because so brilliant.

> [@Find Value from Previous Row](https://community.glideapps.com/t/find-value-from-previous-row/56330/4):
>
> So I assume you store each place’s address/coordinates? What you can do is this: Create an index for each row, as described below Please note that the index should be related to each “trip” only, since you want to index each row based only on their respective list. You should have a “Trip ID” that is unique to each trip. Create a Math column, name it “Previous Index”, take the index from the 1st step, minus 1. Create a Template column, name it “Previous Index Temp”, the template should j…

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 9:16am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/15 "2023-09-13T09:16:40Z")

</div>

But…one more question.  
Do you know any ‘hack’ to make the button up and down prettier ?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/2/e2d2a2e99c862be9d496be359f6369ce010189ca.png)

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 9:17am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/16 "2023-09-13T09:17:46Z")

</div>

How do you define “prettier”? That looks fine to me.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 9:18am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/17 "2023-09-13T09:18:53Z")

</div>

or maybe different color? or not in box?

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 9:20am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/18 "2023-09-13T09:20:12Z")

</div>

Unless you have access to CSS, that’s not doable, but I would keep it as is.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [September 13, 2023, 9:23am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/19 "2023-09-13T09:23:12Z")

</div>

oh i remember the last version we simply can use it on rich text right?

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [September 13, 2023, 9:27am UTC](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026/20 "2023-09-13T09:27:03Z")

</div>

Only on Classic Apps. In the new apps, you only have access to Glide’s CSS input on Business/Enterprise.

That said, I don’t think that design looks bad.

[Next page](https://community.glideapps.com/t/auto-numbering-sorting-with-previous-row/66026.md?page=2)
