Problem

      Hi everyone, I would like to request natural sorting through Realm because my client needs the orders to be sorted ascending naturally by sequence. A sequence is a string that consists of alphanumeric characters, for example 'ABC123'. The clients expect it to be sorted like this: ['ABC123', 'ABC4'] => ['ABC4', 'ABC123']

      Currently I'm sorting the Realm.Results from useQuery with useMemo like this:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const orders = useQuery(Order)
      
      const sortedOrders = useMemo(() => {
        const _orders = orders.toJSON()
        _orders.sort((a, b)=> {
          return a.sequence.localeCompare(b.sequence, undefined, {
            numeric: true,
            sensitivity: 'variant',
          })
        })
        return _orders
      }, [orders])
      

      But this would add a layer of complexity to the query, and although it would solve the problem for now, the client will request more sorting options in the future so it would become increasingly more difficult to sort with useMemo as opposing to passing an array to the sorted function from Realm.
      It would be so much better if I can sort it naturally in Realm instead, like this:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const orders = useQuery(Order, collection => {
        return collection.sorted([
          ['sequence', false, true],
        ])
      })
      

      Where the third parameter would be natural?: boolean

      Or we can change the sorted function to receive an options object like this:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const orders = useQuery(Order, collection => {
        return collection.sorted([
          {
            field: 'sequence',
            descending: false,
            natural: true,
          },
        ])
      })
      

      Hope this gets implemented soon, thank you!

      Solution

      No response

      Alternatives

      No response

      How important is this improvement for you?

      I would like to have it but have a workaround

      Feature would mainly be used with

      Local Database only

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: