react-bootstrap-table / react-bootstrap-table2

Next Generation of react-bootstrap-table
https://react-bootstrap-table.github.io/react-bootstrap-table2/
MIT License
1.27k stars 431 forks source link

How to scroll to a row programatically #1407

Open nishanthkothuru opened 4 years ago

nishanthkothuru commented 4 years ago

Based of the user input, one the table loads, I need to select a particular row. I am able to accomplish this using the following code

selectRow={{ mode: 'radio', clickToSelect: true, selected: [selectedRow] }}

But row is not in the user display due to the size of the panel where the table is loaded. Is there a way to scroll to the selected row programmatically?

In other words, how can I access the element id/ref of the row/cell selected to pull the concerned record into the display?

lavania-aditya commented 4 years ago

@nishanthkothuru use attrs: (cell, row, rowIndex, colIndex) => ({ id: `${rowIndex}${colIndex}` }) to prove id to the specefir column, and you can find the element by const elem=get element by id (id name), and use any third party library to scroll by id: https://www.npmjs.com/package/react-scroll

an alternative way of dining this is if you know the instance of your row you can use ref to create a reference in the world of react and scroll into view to scroll through the particular thing, ex:

ref={this.newDate} // in div or span use formatter
private newDate: any;  // in class in .tsx only
this.newDate = React.createRef(); // in constructor in .tsx only
this.newDate.current.scrollIntoView(); //to scroll