Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Javascript sort by multiple categories

I need to make a sort by Status and ETA, I've managed to make the sort by Status by can't figure out to make it also by ETA. What I've done so far is only sorting by Status, it should sort by ETA also, but I can't manage to figure out why this solution is not working.

Here is my code:

const data = [
        {
          id: 1,
          name: "Delivery 1",
          amount: 3,
          status: "active",
          eta: 15
        },
        {
          id: 2,
          name: "Delivery 2",
          amount: 5,
          status: "pending"
        },
        {
          id: 3,
          name: "Delivery 3",
          amount: 3,
          status: "active",
          eta: 10
        },
        {
          id: 4,
          name: "Delivery 4",
          amount: 4,
          status: "upcoming"
        },
        {
          id: 5,
          name: "Delivery 5",
          amount: 3,
          status: "active",
          eta: 25
        },
        {
          id: 6,
          name: "Delivery 6",
          amount: 3,
          status: "active",
          eta: 5
        }
      ];

<tbody>
  {searchResults.sort((a, b) => a.eta > b.eta ? 1 : -1 && statusOrdered.indexOf(a.status) - statusOrdered.indexOf(b.status)).map(el => {
    return (
    <tr>
      <td>{el.id}</td>
      <td>{el.name}</td>
      <td>{el.amount}</td>
      <td>{el.eta}</td>
      <td>{el.status}</td>
    </tr> 
    );
  })}
  </tbody>
    </table>
  );
};

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just to explain you how it will look like, consider the following example.

(a.eta - b.eta) || (a.status - b.status)

So you need to use || instead of &&.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!