Document sorted() better

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Won't Fix
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      See this issue for details: https://github.com/realm/realm-js/issues/306

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

            Assignee:
            Unassigned
            Reporter:
            Brian Munkholm (Inactive)
            Archiver:
            Marc Greenfield

              Created:
              Updated:
              Resolved:
              Archived: