I am new to the react. Here I have is a table which has some td
, now on click of the button I add one more td in that table. Now, the table is also scrollable,so , what I want is that table scroll should be at top when we add a new row. So, that user will come to know easily that the row has been added .
I tried is ,
I have a container,
JobList.js
constructre(props){
super(props);
this.myRef = React.createRef();
}
componentDidMount() {
if (this.state.operationType) {
this.props.changeOperationType(this.state.operationType);
}
if (!this.props.jobs) {
this.props.fetchUserJd();
}
this.myRef.current.scrollTo(0, 0);
}
render() {
return(
<UserJobsTabel
jobList={filteredList}
sortAscending={this.sortData}
sortCountAndScoreAscending={this.sortNumbersAscending}
addNewRow={this.addNewRow}
isRowAddingEditorVisible={this.props.isRowAddingEditorVisible}
removeRow={this.removeRow}
refer={this.myRef}/>
)
}
UserJobsTable.js
<div className="table-responsive">
<table>
<thead>
<tr className="text-center">
<th></th>
<th scope="col">Technology<i className="fa fa-fw fa-sort sort-icon"></i></th>
<th scope="col">Total Resumes<i className="fa fa-fw fa-sort sort-icon"></i></th>
<th scope="col">Job Title<i className="fa fa-fw fa-sort sort-icon"></i></th>
<th scope="col">Total Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
<th scope="col">Average Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
<th></th>
</tr>
</thead>
<tbody className="text-center" ref={props.refer}>
</tbody>
//remaining
</div>
So, Here I am getting the error that scrollTo is not a function.
So, is there any way to do this ? Or what is it that I am doing wrong.