[Feature] Manual firing fetchData
Manual fetching data may be useful in interactive tables. For example, data on server is updating every 1 minute and its will be good to not unmount(or change sort/page/filter etc) table for fetch this data.
You should fetch that data outside of ReactTable. onFetchData is not really meant for real-time updates. It is designed to let you know when the USER has taken an action that requires you to get new data - not for when the server has added data and you want to refresh ReactTable.
State management tools like Redux or MobX are meant for that type of work.
@gary-menzel What about refresh table button? User make action in this case.
You loaded the data externally and passed it into ReactTable. You should also reload the data externally and pass it in.
React works by observing when properties change to refresh data.
There is no action that a use can take INSIDE ReactTable to request a reload of data. It is an external action. Your data came either from props you passed in or state you initialised in something like componentDidMount in the Component that is wrapping ReactTable. That is where the data should be reloaded.
@MAKARD, try use react ref and statefull react component:
class TableWithRefresh extends React.Component {
updateTableData = () => this.table.fireFetchData();
render() {
const { tableProps } = this.props;
return (
<div>
<button onClick={this.updateTableData}>Refresh data</button>
<ReactTable
{...tableProps}
ref={(instance) => { this.table = instance; }}
/>
</div>
);
}
}
If needed you can also use ref with stateless components, see https://reactjs.org/docs/refs-and-the-dom.html#refs-and-functional-components
The instance can now be accessed from render props https://github.com/react-tools/react-table#functional-rendering
@gary-menzel
You loaded the data externally and passed it into ReactTable. You should also reload the data externally and pass it in.
this isn't fully true in all cases. react-table owns/controls state too. that is, i passed it onFetchData={this.fetchData}, react-table owns the stateful data that gets passed in as args to onFetchData. consequently, i can't just load my own data without a bump from react-table sharing its state with me
@0777101, great find. thanks for finding that!
for future viewers, https://github.com/react-tools/react-table/issues/808#issuecomment-373673915 works, even if calling into an unofficial API is a little dicey