Sorting numbers in Device State Table

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?

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.

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:


and after it looks like this:

Let me know if that works for you! :smiley:

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}}

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.

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