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.

sort-by prop Numerical Ordering Issue

See original GitHub issue

I am using an ais-refinement-list and running into an issue where I cannot properly control the sort-by prop. I am specifying :sort-by="['isRefined:desc', 'name:asc']" but the results are returning in the following order:

  • 1000-2000
  • 10001-11000
  • 11001-12000
  • 12001-15000
  • 15001-20000
  • 20001-50000
  • 2001-3000
  • 3001-4000
  • 4001-5000
  • 5001-6000

It would be helpful to be able to tell Algolia to sort these results like you would sort actual numbers, like this:

  • 1000-2000
  • 2001-3000
  • 3001-4000
  • 4001-5000
  • 5001-6000
  • 10001-11000
  • 11001-12000
  • 12001-15000
  • 15001-20000
  • 20001-50000

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
intrepidwscommented, Apr 3, 2018

Thanks.

For anyone faced with a similar issue, this is how we fixed it.

First, added a sort method:

const app = new Vue({
    el: '#app',
    data: function() {
        return {
            query: ''
        }
    },
    methods: {
        numberAsc: function (a, b) {
            if (a.isRefined && b.isRefined) {
                return a.name.split('-')[0] - b.name.split('-')[0]
            } else if (b.isRefined) {
                return 1
            } else if (a.isRefined) {
                return -1
            } else {
                return a.name.split('-')[0] - b.name.split('-')[0]
            }
        }
    },
    components: {
        'ais-event-wrapper': AisEventWrapper
    }
});

Then referenced this sort method:

<ais-refinement-list attribute-name="attribute-name" :limit=15 :sort-by="numberAsc"></ais-refinement-list>
0reactions
Haroenvcommented, Apr 3, 2018

That’s what I meant, thanks for sharing your solution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sorting by numerical order - Power Platform Community
I want to display all the teams in numerical order so Team n°1 first ... property to convert TeamNumber to a Number type...
Read more >
Sorting and ordering issue lists - GitLab Docs
When you sort by Weight, the issue list changes to sort ascending by the issue weight. Issues with lowest weight are first, and...
Read more >
Sorting an array of objects by property values - Stack Overflow
One issue I have with this is that with reverse=false, it will sort numbers as 1,2,3,4... but Strings as z,y,x... – Abby. Apr...
Read more >
SortBy - Wolfram Language Documentation
sorts the elements of list in the order defined by applying f to each of them. breaks ties by successively using the values...
Read more >
Help:Sorting - Wikipedia
This page is about sorting of tables. For sorting of categories, see Wikipedia:Categorization § Sort keys. For sorting of article sections, see WP:ORDER....
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