'I created a table with react but now I need to send them data from my backend, does anyone know how I can do this?
Code Table: I am creating a table that receives parameters as shown in the table header, now I need to get them from the endpoint below, how can I do the data mapping? in the endpoint it receives a date and according to this it shows the data
import React from 'react';
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table';
import 'react-super-responsive-table/dist/SuperResponsiveTableStyle.css';
const TableComparativeSale = ({ data }) => {
console.log(data);
return (
<Table
id="tabla-comparativa"
className="table table-striped table-bordered"
>
<Thead>
<Tr>
<Th>Id</Th>
<Th>Tienda</Th>
<Th>Tipo de Tienda</Th>
<Th>Fecha año anterior</Th>
<Th>Fecha año actual</Th>
<Th>Estado Crecimiento</Th>
<Th>Estado Crecimiento</Th>
<Th>Visitas</Th>
<Th>Boletas</Th>
<Th>Conversion</Th>
</Tr>
</Thead>
<Tbody>
{data.map((venta) => (
<Tr key={venta.id}>
<Td>{venta.id}</Td>
<Td scope="row">{venta.nombre_tienda}</Td>
<Td>{venta.tipo_tienda}</Td>
<Td>$2.395.990</Td>
<Td>$ {venta.monto_ventas}</Td>
<Td>+</Td>
<Td>43%</Td>
<Td>{venta.visitas}</Td>
<Td>{venta.boletas}</Td>
<Td>33%</Td>
</Tr>
))}
</Tbody>
</Table>
);
};
export default TableComparativeSale;
Code ENDPOINT node js and mssql
export const TableSales = async (req, res) => {
const pool = await getConnection()
try {
const {fecha} = req.body
const result = await pool.request().query(`exec [COMER].[dbo].intranet_consulta_venta_diaria '${fecha}'`)
pool.close()
res.json(result)
return res.status(200)
} catch (error) {
pool.close()
return res.status(404).json({ msg: JSON.stringify(error) });
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
