Tips on transforming a grouped object into a table organized by column with the help of Lodash

Looking at my array data:

[{ id: '1234', year: 2019 , name: 'Test 1- 2019', rate: 1}, 
 { id: '1234', year: 2020, name: 'Test 2 - 2020',  rate: 2 },
 { id: '1234', year: 2020, name: 'Test 3 - 2020', rate : 3 } 
 ...] 

I am trying to display it in a table with this layout:

<table border="1">
  <tr> 
    <th> 2019 </th>
    <th> 2020 </th> 
  </tr> 
  <tr>
    <td> Test 1- 2019</td> 
    <td> Test 2- 2020 </td> 
  </tr>
  <tr>
    <td>  </td> 
    <td> Test 3- 2020 </td> 
  </tr>

</table>

Can anyone provide suggestions on how to achieve this? Thank you! :)

Update: This is what I have attempted so far:

    <table border="1">
      <tr> 
        <th> 2019 </th>
        <th> 2020 </th> 
      </tr> 
      <tr>
        <td> Test 1- 2019</td> 
          <td>  </td> 
      </tr>
       <tr>
        <td> </td> 
          <td> Test 2 - 2020 </td> 
      </tr>
      <tr>
        <td>  </td> 
        <td> Test 3 - 2020 </td> 
      </tr>

    </table>

I am currently using a simple v-for loop in VueJS to iterate through the array.

<table> 
  <tr> 
     <td> ...year </td> 
  </tr>
  <tr v-for="item in arr">
     <td> {{ item.year == "2019" ? item.name : ""}} </td>
     <td> {{ item.year == "2020" ? item.name : ""}} </td>
  </tr>  
</table>

Answer №1

Check out this solution shared by @cmgchess

The method involves utilizing groupBy followed by extracting the Object values and zipping them with lodash

Access the link for more details: shorturl.at/cdxQ6

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Next.js is causing me some trouble by adding an unnecessary top margin in my index.js file

I started a new project using next.js by running the command: yarn create next-app However, I noticed that all heading and paragraph tags in my code have default top margins in next.js. index.js import React, { Component } from "react"; import ...

Using onchange within an onchange event will not function as intended

When I am in the process of creating 2 dropdown menus filled from a database, the issue arises when the second dropdown is generated after selecting a value from the first one. Upon choosing an option from the second dropdown, my ajax function is triggered ...

The issue of batch-wise data clustering on Google Maps when zooming in or out

//The code snippet provided below initializes a map with specified settings and clusters markers based on the data sent in patches of 10000.// var mapDiv = document.getElementById('newmap'); map = new google.maps.Map(mapDiv, { center ...

Navigating through drop-down menus using jQuery

I need help with a JavaScript script that can calculate the total number of points based on selected checkboxes and dropdown values. Currently, my script is able to iterate through checkboxes and assign 1 or 2 points based on their classes, but I'm st ...

The Node.js application encounters a blank response when making a GET request to the API

As a newcomer to node.js, I'm attempting to describe the issue at hand as clearly as possible. If clarification is needed, please let me know. In my current node.js project, I am faced with a challenge where I need to take a code received from the re ...

The function insertAdjacentHTML does not seem to be functioning properly when used with a

I am working with a parent element that contains some child elements. I create a DocumentFragment and clone certain nodes, adding them to the fragment. Then, I attempt to insert the fragment into the DOM using the insertAdjacentHTML method. Here is an ex ...

Navigating to the parent node in a treeview within the wijmo flex grid: a step-by-step guide

Utilizing the wijmo flex grid, I've successfully created a tree view for my data. I can determine if a specific node has children and its level, but I'm struggling to navigate to the parent node from a given one. Additionally, I am able to retrie ...

Using TypeScript, what is the best way to call a public method within a wrapped Component?

Currently, I'm engaged in a React project that utilizes TypeScript. Within the project, there is an integration of the react-select component into another customized component. The custom wrapped component code is as follows: import * as React from " ...

Find the Nearest Value with Jquery and Swap Out the Div

When users complete a form and click "continue," they move on to the next section. At the top of the page, a heading indicates that the previous form is finished. If users click on the heading, it expands the completed form so they can edit it. For instan ...

Is it possible to concurrently hot module reload both the server (.NET Core) and client (Angular)?

Using the command 'dotnet watch run' to monitor changes in server code and 'ng build --watch' for Angular code updates has been successful. It rebuilds the code correctly into directories "bin/" and "wwwroot/" respectively. myapp.cspro ...

JavaScript interprets code differently each time it runs

After returning to work this morning, I encountered some strange behavior that disappeared after restarting the server. Despite my efforts, I couldn't recreate it. So, consider this question "solved" and feel free to delete it if necessary. I'm n ...

Modifying the color of a specific div using jQuery

I am attempting to develop a function that changes the background color of a div when a user clicks on it and then clicks on a button. The value needs to be saved as a variable, but I'm having trouble getting it to work because it keeps saying that th ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...

Clickable list element with a button on top

Within my web application, there is a list displaying options for the user. Each 'li' element within this list is clickable, allowing the user to navigate to their selected option. Additionally, every 'li' element contains two buttons - ...

Issue with event listener arising once elements have been loaded into the dom

I have a project where I want to click on a category card to obtain its id and then redirect to the movies screen. I understand that using row.eventlistener() in index.js executes before the elements are rendered, causing the id not to be captured. How ca ...

What is the best way to incorporate a loop into a React return statement?

After learning React, I decided to develop the Tic-tac-toe game following the official documentation. There were extra tasks listed below the "Tutorial" section, and one of them was: "Rewrite the Board component to use two loops to generate the squares in ...

The correct way to create a Reaction Collection

I'm trying to set up an event where a user triggers a reaction with either a Check mark or X. However, I keep encountering an error that the function doesn't exist for the message object. I attempted to switch back to awaitReactions but it didn& ...

Verify and send form without reloading the page

I am currently facing an issue with jQuery validation and ajax form processing. My goal is to prevent a page refresh by using ajax, but I am struggling to determine the appropriate placement for the ajax code within the validation function in order to ensu ...

Failed Cross-Origin Request Sharing in AngularJS 1.4

I'm currently working with AngularJS version 1.4.3 and here is the code snippet I am using: angular .module('app', []) .run(run); function run($http) { a = $http({ method: "GET", url: 'http://127.0.0 ...

Refreshing the page or directly loading it results in a blank screen being displayed

Despite researching various solutions to this common issue, none seem to work for me. Let's dive into it. I've developed a Vue 2 application integrated with Express running on AWS Amplify. When testing the app locally in 'dev' mode (np ...