[Vuejs]-Vuejs orderby property value in computed returning 9 items

1๐Ÿ‘

โœ…

You should map your status values from Strings to Numbers, like this:

computed:
{
  objectList()
  {
    const statValues = [
      'OK',
      'inProgress',
      'Completed',
    ];
    // we need 2 "slice()" - first one is because "sort()" will otherwise modify the list (which is an unwanted side effect for a computed property)
    // the other "slice()" is the real one that will return the 9 items for the current "page"
    return this.list.slice().sort((a, b) =>
    {
      const statA = statValues.indexOf(a.status);
      const statB = statValues.indexOf(b.status);
      return statA - statB;
    }).slice(9 * this.page);
  }
}
๐Ÿ‘คIVO GELOV

Leave a comment