# Sorting numbers in Device State Table

**URL:** <https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937>\
**Category:** Feature Request\
**Created:** [February 15, 2023, 4:58pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937 "2023-02-15T16:58:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [February 15, 2023, 4:58pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/1 "2023-02-15T16:58:03Z")

</div>

I have a device state table, which shows a list of assets, and one or two key metrics.

If I sort by some field which is a number, the sort is applied as if it’s a string rather than a number.

Anything starting with a 9 is bumped to the top, and 1 to the bottom.  
Numbers with 5,000 or 5,000,000 are somewhere in the middle.

Is there something I can do to achieve this, or would this be a fix on Losant’s side?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/78c06e277c4fdd83eabeb930cdd3839ea8ca51c9.png)

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [February 15, 2023, 6:25pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/2 "2023-02-15T18:25:36Z")

</div>

Hi @ChrisGM !

This is a great suggestion. Currently, the only column in the Device State Table that sorts by the underlying data (rather than the rendered string) is the `Timestamp` column.

At this time, the only workaround I can think of would require reformatting the underlying data (adding leading/trailing zeros to pad the numbers so that they’re all the same length). I’m assuming this isn’t a viable solution for your use-case.

I’ll file a feature request and follow up on this thread if I have an update.

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [February 15, 2023, 7:08pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/3 "2023-02-15T19:08:15Z")

</div>

Hi @ChrisGM

I was able to reproduce your issue, and I think I have a work around for you. In the cell template of your attribute column try adding `{{ format value 1 }}` instead of just the default which is `{{ format value }}`.

Without the `1` I get a block that sorts like this:

 ![Screenshot 2023-02-15 at 2.06.37 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/7053743dc0689a1c83cd1681b4db40710fa4a599.png)  
and after it looks like this:  
 ![Screenshot 2023-02-15 at 2.06.29 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/b/b23c724045346ddf4ae5aad8cb36ef059289cc91.png)

Let me know if that works for you! 😃

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [February 17, 2023, 12:13pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/4 "2023-02-17T12:13:16Z")

</div>

Thanks @Erin_Thompson,

This fixes the sort issue!

This format removes any 1,000 separators and decimal place control.

If I was using something like this before:  
{{format value ‘0,.2f’}}  
Is there a way of combining this with:  
{{format value 1}}

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [February 17, 2023, 4:06pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/5 "2023-02-17T16:06:11Z")

</div>

I think the reason the sort is messed up is because of the commas. You are sorting by strings and not by numbers. So if you can go without the commas, doing `{{format value ‘.2f’}}` will allow you to have the decimal control and the sort.

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [February 17, 2023, 5:40pm UTC](https://forums.losant.com/t/sorting-numbers-in-device-state-table/4937/6 "2023-02-17T17:40:13Z")

</div>

{{format value ‘.2f’}} then starts treating the numbers as strings again in terms of sort
