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.

Result.sorted reverse property isn't working

See original GitHub issue

I’m trying to sort my ListView by date with the newest first. The documentation says .sorted takes a reverse param, but it isn’t making any difference.

My code:

let items = this.db.objects(ITEMS_TABLE);
items.sorted('dateUpdated', true);

I get the same sort order with items.sorted('dateUpdated', true); and items.sorted('dateUpdated', false);

This is with Realm 0.10.0

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
appdencommented, Mar 4, 2016

@asamiller sorted() returns a new Results instance, so you probably need to change to something like this:

let items = this.db.objects(ITEMS_TABLE).sorted('dateUpdated', true);
1reaction
mikaelfscommented, Sep 9, 2017

Flash forward a year later and I stumbled on the same problem. The Realm JS documentation should have mentioned in more details on how to sort properly in reverse order.

In order to perform sorting in reverse order, the .sorted() method should be invoked via fluent API chaining without intermediary variable assignment

Improper reverse sorting:

let items = realm.objects('Article').filtered('createdAt > $0', twoDaysAgo);
const reverseSortedItems = items.sorted('createdAt', true); //will not work
console.log(reverseSortedItems);

Proper reverse sorting:

const sortedItems = realm.objects('Article').filtered('createdAt > $0', twoDaysAgo).sorted('createdAt', true); //sorted in reverse order by date
console.log(sortedItems)
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - sort() and reverse() functions do not work
The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list.
Read more >
Save a sort order with a table, query, form, or report
Last-applied sort orders · Press F4 to display the property sheet. This step is unnecessary if the property sheet is already displayed. ·...
Read more >
How to use sorted() and sort() in Python 3 - KnowledgeHut
A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result...
Read more >
Sort Rows to Organize Your Data - Smartsheet Learning Center
To organize your data in ascending or descending order, use the Sort Row command.
Read more >
Pandas Sort: Your Guide to Sorting Data in Python - Real Python
By passing False to ascending , you reverse the sort order. Now your DataFrame is sorted in descending order by the average MPG...
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