[Vuejs]-Vue.js not arranging elements numerically?

0👍

Ahhhh seems like I found the answer after some serious tinkering with the code.
I changed it to the following:

computed: {
    sortedlists() {
      return this.lists.filter(
        list => list.name.includes(this.filterByName)
      ).sort(
        (a, b) => a[this.sortBy] - b[this.sortBy]
      );
    }
  }

0👍

You need to sort by rank as a number and not as a string. Alphabetical order is exact that you got: 1,10,100,11,2,20,21.

const sortedList = lists.splice().sort((x1, x2) => (parseInt(x1.rank) - parseInt(x2.rank)))

Leave a comment