I'm preparing a react-table and there is a column of buttons. When clicked, there is another column that updates according to the row number that was clicked.
I want to remove the separate column to show the data and have it update the column which has the button in it. Therefore once clicked, the data obtained will replace the button in that particular row. How do I do this?
this is the table format I currently have. So when I click the button, 'API calls in last month' gets updated accordingly.
{
Header: 'Click to get API info',
accessor: 'click-me-button',
Cell: ({ row }) => (
<button onClick={(e) => this.handleButtonClick(e, row)}>Click Me</button>
)
},{
Header: 'API calls in last month',
accessor: 'lastapicalls',
Cell: row => <div style={{ textAlign: "center" }}>{row.value}</div>
}
I want to remove the column 'API calls in last month' and update 'click-me-button' column with that info obtained by clicking the button (by replacing the clicked button with the obtained data)
The code for obtaining data for now is as follows
handleButtonClick(e, rowInfo) {
axios({
method: 'get',
url: 'http://localhost:8080/info/search/lastapicalls/'+rowInfo.tenant_domain,
auth: {
username: this.state.user,
password: this.state.pass,
}
})
.then(response => this.setState({ retrievedapicalls: response.data },
() => {
this.setState(oldState => {
let data = oldState.data.slice();
let copy = Object.assign({}, data[rowInfo._index]);
copy.lastapicalls = this.state.retrievedapicalls;
copy.selected = true;
data[rowInfo._index] = copy;
return {
data
};
}
);
}))
}
The state 'data' contains the information necessary to fill the table.