Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

68
Vistas
How to map over array of colors for a datatable in React?

I'm using material ui table to map over data from API but each table row has a progress bar. I want to be able to give the progress bar different colors. Here's the code below...

const BorderLinearProgress = withStyles((theme) => ({
 
  bar: {
    borderRadius: 5,
    backgroundColor: "red"
    
  },
}))(LinearProgress);




export default function FeatureTwo() {
  
  const [hmoName, setHmoName] = useState([]);
  const [hmoProgress, setHmoProgress] = useState([]);

  const getHmo = async () => {
    try {
      //API call
    } catch (err) {
      console.log(err);
    }
  };

  

  

  return (
    
     
        
        <Table aria-label="customized table">
          <TableHead>
            <TableRow>
              <StyledTableCell align="left">HMO</StyledTableCell>
              <StyledTableCell align="left">Enrollment Progress{''} (Percent %)</StyledTableCell>
            </TableRow>
          </TableHead>
          <TableBody>
            <TableRow>
              <TableCell align="left" >
                {hmoName.map((name, idx) => {
                  return (
                    <button key={idx}>
                      {name}
                    </button>
                  );
                })}
              </TableCell>

              <TableCell align="left" >
                <div>
                 
                    {hmoProgress.map((number, idx) => {
                      return (
                        <div>
                        <div>
                          <span key={idx}>
                            {parseInt(number).toFixed(0)}
                          </span>
                          <span >
                            Progress
                          </span>
                          </div>

                          <span>
                            <BorderLinearProgress
                              variant="determinate"
                              value={parseInt(number).toFixed(0)}
                            />
                          </span>
                        </div>
                        
                      );
                    })}
                  </div>
               
              </TableCell>
            </TableRow>
          </TableBody>
        </Table>
     
  );
}


BordeLineProgress has a background color set to red, all the progress bar in each row has the BC red. I want to set different colors for each progress bar for each row.

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.