Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To compute the sum of data in the CRUD table application using React JS, Node JS, and Bootstrap, you can follow these steps:

  1. In the server-side Node JS code, retrieve the data for the table from the database and store it in an array.

  2. Sum up the values of the field you want to compute the total for in a variable.

  3. Pass the data and the total to the React component as props.

  4. In the React component's render method, display the table data and the total in separate elements using Bootstrap.

    Example:

// Server-side code (Node JS)

const data = [ { id: 1, name: "Product 1", price: 10 }, { id: 2, name: "Product 2", price: 20 }, { id: 3, name: "Product 3", price: 30 } ];

const total = data.reduce((sum, row) => sum + row.price, 0);

// React component

import React from 'react'; import Table from 'react-bootstrap/Table';

const TableComponent = ({ data, total }) => (

{data.map((row) => ( {row.id} ))}
ID Name Price
{row.name} {row.price}
Total: {total}
);

export default TableComponent;