Is it possible to arrange JSON Objects vertically on a webpage using tables, flexboxes, divs, and Javascript?

Within my JSON data, I have multiple products defined. My goal is to loop through this JSON and display these products side by side on a web page for easy comparison. Initially, I envision structuring them in columns and then rows:

https://i.sstatic.net/KyPTn.png

Currently, I can accomplish this using HTML divs and flexboxes with code similar to:

<div style="display:flex">
     <div id="Sidebar">
          <div class="Data_1">...</div>
          <div class="Data_2">...</div>
          <div class="Data_3">...</div>
          <div class="Data_4">...</div>
          ...
     </div>
     <div id="Product_A">
          <div class="Data_1">...</div>
          <div class="Data_2">...</div>
          <div class="Data_3">...</div>
          <div class="Data_4">...</div>
          ...
     </div>
     <div id="Product_B">
          <div class="Data_1">...</div>
          <div class="Data_2">...</div>
          <div class="Data_3">...</div>
          <div class="Data_4">...</div>
          ...
     </div>
     <div id="Product_C">
          <div class="Data_1">...</div>
          <div class="Data_2">...</div>
          <div class="Data_3">...</div>
          <div class="Data_4">...</div>
          ...
     </div>
</div>

If any product feature includes a long string, I want the height of adjacent cells in other products and the sidebar to adjust their heights accordingly.

https://i.sstatic.net/qfhlF.png

I am aware that I can achieve this structure using an HTML table, but it's not ideal for dynamically adding/removing products or making them draggable since tables are primarily row-oriented. I prefer the flexibility to add, remove, drag, filter, and sort products easily, which seems more suitable with divs or flexboxes.

https://i.sstatic.net/WuwuF.png

My queries :

  • Is there a way to organize a table first in columns and then in rows?
  • How can I ensure all product lines align in height when using divs or flexboxes?
  • Any alternative suggestions for structuring such content or utilizing JavaScript to simplify this process?

Answer №1

To accomplish this task, implement the max-height property and loop through products within a div or ul>li container. Provide code examples for further assistance.

Answer №2

To ensure the product container has a minimum height, you can set this property in the CSS and then use a loop to display each product from your json data.

products.forEach(product =>
  <div>
    <span> product.name </span>
  </div>

By setting a min-height on the product container, it will adjust its size based on the length of the json data provided, ensuring all contents are displayed correctly.

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

Tips for grouping radio buttons that span multiple rows within an ag-grid

I am currently working on a grid layout that consists of multiple rows, with each row containing a radio button as illustrated in the snapshot below: https://i.sstatic.net/O8i0r.png Here is the code snippet for the column definition of the radio button: ...

An issue occurred while attempting to execute a function in AngularJS

Currently, I am in the process of developing a cross-platform application using AngularJS, Monaca, and Onsen UI. My current challenge involves calling a function in my controller from an ng-click() event on my view. However, upon clicking the button that ...

Tips for creating a mock for a function that yields a JSX Element

I am facing a problem where I have a function that returns a JSX Element. Here is a snippet of the code: myFunction.jsx const myFunction = (props) => { // ... do something with props return <MyElement {...newProps} /> } // MyElement.j ...

Steps for combining two collections into a single output in MongoDB with Node.js

My MongoDB collections consist of data that I need to merge using the $lookup operation. However, the result I get contains a nested array structure that is not ideal. I am looking for a solution to format the result as shown below: First collection locati ...

Using axios to pass parameters in a post request

In my webpack project, I am currently using vue-resource for ajax calls. Everything works perfectly with "get" calls, but when I try a post request, my PHP file does not receive any parameters. Even when I use var_dump($_POST), it just gives me an empty ar ...

How to update the date format in v-text-field

I have run into an issue while working on a Vue.js project that utilizes Vuetify. The problem lies with the default date format of the v-text-field when its type is set to "date." Currently, the format shows as mm/dd/yyyy, but I need it to display in the y ...

Switching a conditional className to a styled component

Currently, I am in the process of converting my project from plain CSS to styled components using styled-components. So far, I have successfully converted all of my components except for one. I have looked at various examples on Stack Overflow but none of ...

Exploring the integration of data from two Firestore collections using JavaScript

I manage two different types of collections, one being called CURRENCY-PAIR and the other Alerts. The collection CURRENCY-PAIR includes the following information: Currency-Pair Name Currency-AskPrice Currency-BidPrice On the other hand, the Alerts colle ...

Using Sinon with Ember to create a Mock Server

I am looking to test my controller by making an ajax call to my backend using Jasmine and Sinon. To fake my backend server with Sinon, I attempted the following approach: describe("fake server", function() { var server; beforeEach(function() { this ...

Updating data in a SQL database using PHP when a button is clicked

This Question was created to address a previous issue where I had multiple questions instead of focusing on one specific question Objective When the user selects three variables to access data, they should be able to click a button to modify one aspect o ...

The header section on a website not behaving as expected in the Chrome browser

For my website, I want it to look like this in Internet Explorer: https://i.stack.imgur.com/hSkVM.png ^^ This is the IE view However, in Chrome, it displays like this: https://i.stack.imgur.com/noQw8.png The issue is with the Top bar on Chrome showing co ...

What is the best way to create an express route for a delayed string response that is loaded only after an API call promise is fulfilled?

app.get(`/${sumName}`, async (req, res) => { const link = `https://na1.api.riotgames.com/lol/league/v4/challengerleagues/by-queue/RANKED_SOLO_5x5?api_key=${RiotKey}` const response = await fetch(link); let data = await response.j ...

Disabling the button add-ons functionality in Bootstrap 3 for mobile devices

I am facing a challenge with my website that has a visually appealing jumbotron and an enticing email signup call to action bar. The issue arises from the fact that my site is bilingual, catering to both German and English speakers, causing confusion with ...

Ways to incorporate useEffect within a function or the other way around

Currently, I am facing an issue with my code. I have a function that handles the onChange event to retrieve the input value. Additionally, I have another function that searches for items in an array based on the value from the input and then renders a comp ...

Tips for saving and accessing Shopping Cart items using localstorage

As I develop a shopping cart for an e-commerce site, I aim to utilize browser localstorage to store the products. The functions that have been added to my code include: - addToCart(): triggered when the "Add to Cart" button is clicked. - addProduct(): ...

Once the image is loaded, cropped, and displayed on the canvas, what is the best way to implement image rotation functionality for the user before converting it to base64?

My process involves cropping images to a square shape and drawing them onto a canvas. if(img.height >= img.width) { ctx.drawImage(img, 0, 0, 110, 110 * img.height / img.width); } else { ctx.drawImage(img, 0 , 0, 110 * img.width ...

Enforce the retrieval of all fields, even those that have been overridden

I have a query that utilizes mongoose and involves a select operation. The model's schema is configured to exclude two specific fields, like so: contents: { type: String select: false }, password: { type: String select: false } Howev ...

What is the best way to make a selected link stand out with a highlight?

I'm having an issue with the code below that is supposed to keep the selected link highlighted, but it only flashes the green color on click. Can someone help me figure out what's going wrong here? #sidebarContent a:active{ background-colo ...

"Caution: Please be aware of potential header errors when accessing a static map through AJAX

When attempting to retrieve a static map image using AJAX to check for errors, I encountered the following message: Refused to get unsafe header "x-staticmap-api-warning" (seen in Chrome) I am not very familiar with headers, but it appears that they nee ...

The encoding of Node.js using npm

Looking to install the validate .json file below using npm: { "name": "node-todo", "version": "0.0.0", "description": "Simple todo application", "main": "server.js", "dependencies": { "express": "~3.4.4", "mongoose": "~ ...