sortBy not sorting numerical values properly
See original GitHub issueVersion
@nuxt/content: 1.14.0 nuxt: 2.15.7
Steps to reproduce
Use sortBy
on a field such as slug
on some content that has numerical values.
What is Expected?
When filtering by a field with numbers involved, the sorting method should take numbers into consideration. For example, if one is filtering by slug
on a set of files with numerical file names going from 1 to 25 (i.e. 1.md
, 2.md
, 3.md
, etc.), the order of slugs being outputted should be:
1
, 2
, 3
, 4
, 5
, 6
, 7
, 8
, 9
, 10
, 11
, 12
, 13
, 14
, 15
, 16
, 17
, 18
, 19
, 20
, 21
, 22
, 23
, 24
, 25
.
What is actually happening?
1
, 10
, 11
, 12
, 13
, 14
, 15
, 16
, 17
, 18
, 19
, 2
, 20
, 21
, 22
, 23
, 24
, 25
, 3
, 4
, 5
, 6
, 7
, 8
, 9
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Excel not sorting numbers correctly - smallest to largest etc.
I have been helping a friend organize a excel file with 4 digit numbers. These numbers are in the 6000 to 8000 range....
Read more >Excel Not Sorting Numbers Correctly (4 Reasons with Solutions)
Reason 3: Numeric Values Accidentally Formatted as Text and Not Being Sorted Properly. We get another interesting problem here. In our dataset, ...
Read more >Why sort does not sort by value? - Google Support
If column E is sorting as you have shown in your example then it means column E is not a numeric column but...
Read more >Why does Excel sort 'numbers' incorrectly • AuditExcel.co.za
The reason this happens is because Excel has decided that the 'numbers' are actually text and so it is sorting the 'text'. So...
Read more >Excel not sorting correctly (off of a formula) - YouTube
How to SORT Data in Excel | 7 Tips · Excel Won't Sort Dates Correctly - The Solution! · Combine data from different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ElnuDev @lustremedia
Every property of document object is a string.
https://github.com/nuxt/content/blob/0b6a7be6f6287cde880b0d37c88e6461efa167ff/packages/content/types/content.d.ts#L6-L13
You parse slugs or markdown files as numbers, but that’s just because you are a human, not a computer. I believe it’s reasonable to assume that slugs are string, so that Nuxt Content can simplify the situation.
This will not going to implement in Content V1, But it is already supported in Content V2. https://github.com/nuxt/content/issues/1074
I’m closing this issue in favor Content V2 and new sort syntax.