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

196
Views
Rango de filas de la tabla HTML en reactjs

estoy confundido cuando uso el mapa y quiero hacer una tabla como esta

mesa

con datos

 const arr =[{ no: 1, name:'david', fruit: 'apple', type:[{ typeName:'red apple'},{typeName:'green apple'}] }, { no: 2, name: 'david', fruit: 'orange', type:[{ typeName:'mandarin orange'},{typeName:'bergamot orange'}] } ]

ya lo intenté, pero me quedé atascado, solo puedo hacer así

confundo cómo fusionar "david" en esta tabla

Tabla 2

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

0

Resolví este problema. Por favor revisa este código

 // App.js import "./styles.css"; import React, { Fragment } from "react"; export default function App() { const arr = [ { no: 1, name: "david", fruit: "apple", type: [{ typeName: "red apple" }, { typeName: "green apple" }] }, { no: 2, name: "david", fruit: "orange", type: [{ typeName: "mandarin orange" }, { typeName: "bergamot orange" }] }, { no: 3, name: "jason", fruit: "orange", type: [{ typeName: "mandarin orange" }, { typeName: "bergamot orange" }] } ]; let namesArr = {}; const rowSpan = arr.reduce((result, item, key) => { if (namesArr[item.name] === undefined) { namesArr[item.name] = key; result[key] = 1; } else { const firstIndex = namesArr[item.name]; if ( firstIndex === key - 1 || (item.name === arr[key - 1].name && result[key - 1] === 0) ) { result[firstIndex]++; result[key] = 0; } else { result[key] = 1; namesArr[item.name] = key; } } return result; }, []); return ( <div> <table> <tr> <th>no</th> <th>name</th> <th>fruit</th> <th>type</th> </tr> {arr.map((el, index) => ( <tr> <td>{el.no}</td> {rowSpan[index] > 0 && <td rowSpan={rowSpan[index]}>{el.name}</td>} <td>{el.fruit}</td> <td style={{}}> {el.type.length && el.type.map((ele, i) => ( <Fragment> <tr style={{ border: "none", display: "flex", flexWrap: "wrap" }} > <td style={{ border: "none", width: "100%", borderTop: i > 0 ? "1px solid black" : "none" }} > {ele.typeName} </td> </tr> </Fragment> ))} </td> </tr> ))} </table> </div> ); }
 // styles.css table, th, td { border: 1px solid black; border-collapse: collapse; }
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!