question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sortBy not sorting numerical values properly

See original GitHub issue

Version

@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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NozomuIkutacommented, Aug 12, 2021

@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.

0reactions
farnabazcommented, May 23, 2022

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found