question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I get sum values?

See original GitHub issue

I read related issue (https://github.com/AllenFang/react-bootstrap-table/issues/514) and try applied. but it doesn’t work. Please have a look and tell me what I missing.

handleSearchChange (searchText, colInfos, multiColumnSearch) {
      this.refs.getTableDataIgnorePaging();  //'this' is undefined and I have no idea, how do I get current cell values
    }


    render(){
        const options = {
            onSearchChange: this.handleSearchChange.bind(this),
            onFilterChange : this.handleSearchChange.bind(this)
        };
        return (
            <div>
                <h2>Daily Report</h2>
                <div className="data_table">
                    <BootstrapTable data={this.state.data} striped={true} hover={true} trClassName="tr-string" search={true} ref='table' options={options}>
                        <TableHeaderColumn isKey={true} dataField="id" className="no" hidden={true} >No.</TableHeaderColumn>
                        <TableHeaderColumn dataField="Campaign Name" dataSort={true} className="campaign_header" columnClassName="campaign_col" filter={{type: "TextFilter"}}>Campaign Name</TableHeaderColumn>
                        ...
                    </BootstrapTable>
                </div>

                Total Sent : {this.state.sum}
            </div>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
QRMarketingcommented, Dec 5, 2017

AllenFang, ok good! I did a real hack to make it work if others are interested:

I put this in render():

const options = {
        afterSearch: this.afterSearch,
        searchDelayTime: 1500,
        that: this // <- needed this "this" in the search event handler
};

So in afterSearch:

    afterSearch (searchText, result) {
        var count = result.length; 
        var tmpThis = result.pips;
        var pips = 0;             
        for(var i = 0; i < result.length; i++) {
            pips = pips + result[i].Pips; 
        } 
        if(this.that.state.searchText !== searchText) { // <- this stops the infinite loop
            this.that.setState({
                pips: pips,
                count: count,
                searchText: searchText
            }); 
        }
    }

Then somewhere in the react class return below the boostrap table:

<div>
      <center><p>Count: {count} &nbsp;&nbsp;&nbsp;Pips: {pips.toFixed(2)} </p></center>
</div>
1reaction
victoria100commented, Oct 12, 2016

Thanks, @AllenFang I used handleAfterSearch. It works. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SUMIF function - Microsoft Support
You use the SUMIF function to sum the values in a range that meet criteria that you ... To sum cells based on...
Read more >
Excel Sum Function Examples
Select the cell in which you want to see the total · Type an equal sign (=) to start the formula · Type:...
Read more >
How to Sum Values in Excel Automatically or Manually
1. Click the cell you want the sum to appear in and click "=." 2. Type a number or click a cell that...
Read more >
How to sum values by group in Excel? - ExtendOffice
Select next cell to the data range, type this =IF(A2=A1,"",SUMIF(A:A,A2,B:B)), (A2 is the relative cell you want to sum based on, A1 is...
Read more >
How to sum a column in Excel - 5 easy ways - Ablebits
Use the SUM function to total a column · Using the SUM function, you can also automatically total new values in a column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found