Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

ReactJs calculate sum of all values present in Table column

$
0
0

I am having a Bootstrap-table rendering values from service called in componentDidMount().

Example of my table -

  Col1      Col2 Col3   1         2    3   4         5    6   7         8    9  SumValue  15   18 //This last row holds sum of all values

How to calculate SumValue of all the values present in col1 and display in Footer.

Below is the code how i am using react-row for mapping data to rows. And value is the variable holding data of all columns present in json file returned from service, after setting it to the component's state.

    {this.state.value && this.state.value.map(function (value, ind) {                    return <Row key={ind} item={value}></Row>                })            }

Initializing state

   constructor(props){    super(props)    {        this.state ={            value: [],   //Initializing an array            SumValue: '',            default: false,                       }                }

Setting state

  fetch('https://www.serviceUrl.com')   .then(res => res.json())    .then(value => {        this.setState({            value: value.empRecords,  //Here its getting all records from json            default: false        });            })

Let me know guys if any more information is required.


Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>