Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to group orders by date?

now I get items in the table in this order:
11-8-2022
12-8-2022
13-8-2022

but I need to group these items in reverse order, so that the latest date will be on top
13-8-2022
12-8-2022
11-8-2022

Сan you advise me how to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const formattedTable = async (
  orders: Order[],
) => {
  const rows = tableOrders
    .map(
      (orders: Order) =>
        `<tr>
         <td>${DateTime.fromJSDate(orders.deliveryDate).toFormat(
           "dd-MM-yyyy",
         <td>${orders.code}</td>

         )}</td>
}

>Solution :

If your data provider (e.g. backend API) guarantees that table orders are delivered in ascending dates’ order, then in your code you can simply use .reverse() array method as follows:

const formattedTable = async (
  orders: Order[],
) => {
  const rows = tableOrders
    .map(/* ...your map callback function */).reverse()
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading