I am new to React and material UI. I want when the user changes rowperpage from drop-down than I want to scroll at the top of my window. I have used Table in which for pagination I have written code like-
rowsPerPageOptions={[5, 10, 25]}
component="div"
count={users.length}
rowsPerPage={rowsPerPage}
page={page}
onChangePage={handleChangePage}
onChangeRowsPerPage={handleChangeRowsPerPage}
/>
functions called are written like this
const handleChangePage = (event, newPage) => {
window.scrollTo(0, 0);
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
window.scrollTo(0,0);
};
I tried using window.scrollTo(0,0), for handleChangePage its working but for handleChangePerPage its not working.