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.

React Bootstrap Table doesn't update data on componentDidUpdate

See original GitHub issue

Hi,

I’ve got a table that’s empty at the beginning and I want the user to insert data. This is my state:

this.state = {
            ...
            myArray: [],
	    ...
}

Within “myArray” is another array that holds the data to be displayed in the table:

 <BootstrapTable data={this.state.myArray[index].myInnerArray} striped hover condensed pagination options={{noDataText: "No data available"}}>
                            <TableHeaderColumn width='200' dataField="title" dataSort={true} isKey>Title</TableHeaderColumn>
                        </BootstrapTable>

I’ve got a button that opens a modal in which the user can choose from options that will be displayed in the table:

<Button onClick={()=>{this.openModal(index)}}>+</Button>

When you click on an option it triggers “componentDidUpdate”:

componentDidUpdate(){
	const index = this.state.currentIndex;
        if(this.state.myArray[index].myInnerArray.length !== 0)
            return this.state.myArray[index].myInnerArray;
}

The update of state works perfectly fine. It does exactly what it’s supposed to do, however the table doesn’t update (re-render). If I were to add another table with the same array, it displays the data (because it’s not empty anymore). Does your table support data changes on-the-fly? I searched for this feature, but couldn’t find it.

Is there generally a way to update “data” on componentDidUpdate (e.g. by using “setState()”), or do I have to customize your given “insertRow”-modal in order to change data on-the-fly? I’ve tried to do that, but that just a disproportionate effort for it’s intended functionality, in my case.

Thanks for your work!

Issue Analytics

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

github_iconTop GitHub Comments

11reactions
AllenFangcommented, Jun 16, 2017
handleReset() {
  this.ref.table.reset()
}

render() {
  return (
    <div>
        <button onClick={ this.handleReset.bind(this) }>RESET</button>
        <BootstrapTable ref='table' ...></BootstrapTable>
    </div>
  );
}

1reaction
tarimcommented, Jul 21, 2018

Hi @AllenFang,

I have a similar issue. After I update(with popup model) one row, the table doesn’t show the updated status until I click the table. But, the redux store updated record correctly.

Any idea, please?

Thanks,

Read more comments on GitHub >

github_iconTop Results From Across the Web

react bootstrap table not rendering data without refresh
i have used componentdidupdate and componentdidUpdate to render the props data . but nothing is working . the table does not render the...
Read more >
React ref array map - Caritas Castellaneta
The useSelector hook lets React components read data from the store. finally, ... { useState } from 'react' import Table from 'react-bootstrap/Table' import ......
Read more >
React-bootstrap-table rowevent not updating state ...
Coding example for the question React-bootstrap-table rowevent not updating state immediately-Reactjs.
Read more >
BootstrapTable Props · react-bootstrap-table2 - GitHub Pages
Tells react-bootstrap-table2 which column of the data is unique. ... It's the only way to communicate to your remote server and update table...
Read more >
A comprehensive guide to data fetching in React
All of the components render the same data and look the same. I used the traditional <table> HTML element for displaying tabular data...
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