Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table scroll to top of new page #21793

Closed
cl4k opened this issue Jul 14, 2020 · 4 comments
Closed

Table scroll to top of new page #21793

cl4k opened this issue Jul 14, 2020 · 4 comments
Labels
support: Stack Overflow Please ask the community on Stack Overflow

Comments

@cl4k
Copy link

cl4k commented Jul 14, 2020

Hi Guys,
first of all thanks for material-UI, it's really useful!
I'm stuck on this since yesterday ...
I don't found the way to be on the top of new page when you click on next, I always stay at the bottom whatever I do.

I already check on StackOverflow and GitHub, I found this issue which seems to be close: #9186
And I can't find anything on your documentation (I think we should add it haha )

I supposed using ref and callback is the right way, I already try to implement it. However, I'm always stuck at the having the last element and I can't scrollTop to the one of the page

I based my code on Custom pagination actions

Here is an example of my code

function DisplayList(props) {
   var rows = [];
   const data = props.data;
   const tableRef = React.createRef();
   const searchData = props.searchData;
   const setHoverAddress = props.setHoverAddress;

   const classes = useStyles1();

   const [page, setPage] = useState(0);
   const [rowsPerPage, setRowsPerPage] = useState(5);

   const handleChangePage = (event, newPage) => {
       setPage(newPage);   
       if(tableRef.current) {tableRef.current.scrollTop = 0;}
   };

   const handleChangeRowsPerPage = (event) => {
       setRowsPerPage(parseInt(event.target.value, 10));
       setPage(0);
   };


   data.map((result, index) => { // WARNING : slice here which limits the number of results: .slice(0, 5)
       const volulme = Math.round(result.volulme);
       const volulme2 = Math.round(result.volulme2);

       rows.push(
       <div id={index}>
           <ListItem 
           alignItems="flex-start"
           onMouseEnter={e => {
               console.log(index);
           }}
           >
               <Grid container direction="row" spacing={1}>
                   <Grid item xs={5}>

                   {/* <Stage width={150} height={150}>
                       <Layer>
                       <Shape
                           sceneFunc={(context, shape) => {
                           context.beginPath();
                           context.moveTo(20, 10);
                           context.lineTo(120, 80);
                           context.lineTo(120, 140);
                           context.lineTo(22, 140);
                           context.closePath();
                           // (!) Konva specific method, it is very important
                           context.fillStrokeShape(shape);
                           }}
                           fill="#00D2FF"
                           stroke="black"
                           strokeWidth={2}
                       />
                       </Layer>
                   </Stage> */}

                   </Grid>
                   <Grid item xs={7}>
                   <ListItemText
                   primary={
                   }
                   secondary={
                       <React.Fragment>
                       <Typography
                           component="span"
                           variant="body2"
                           display="inline"
                           color="textPrimary"
                       >
                           Solid2 : {volulme2}
                       </Typography>
                       </React.Fragment>
                   }
                   />
                   <ListItemText
                   secondary={
                       <React.Fragment>
                       <Typography
                           component="span"
                           variant="body2"
                           display="inline"
                           color="textPrimary"
                       >
                           Solid : {volulme}
                       </Typography>
                       </React.Fragment>
                   }
                   />
                   <FormControlLabel
                   control={
                       <Checkbox icon={<FavoriteBorder />} 
                       checkedIcon={<Favorite />} 
                       color="primary"
                       onClick={(e) => {
                           if (e.target.checked) {
                               addFavourite(parc_id, 1)
                           } else {
                               removeFavourite(parc_id, 1)
                           }
                       }}
                       name="checkedH" />
                   }
                       label="Enregistrer"
                   />
                   </Grid>
               </Grid>
           </ListItem>
       </div>
       )
   })


   return (
           <Table className={classes.table} aria-label="custom pagination table">
               <TableBody>
               {(rowsPerPage > 0
                   ? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
                   : rows
               ).map((row) => (
                   <TableRow key={index}>
                       <TableCell component="th" scope="row">
                         <div ref={tableRef}>
                           {row}
                          </div>
                       </TableCell>
                   </TableRow>
               ))}
               </TableBody>
               <TableFooter>
                   <TableRow>
                       <TablePagination
                       rowsPerPageOptions={[5, 10, 25, { label: 'All', value: -1 }]}
                       colSpan={3}
                       count={rows.length}
                       rowsPerPage={rowsPerPage}
                       page={page}
                       SelectProps={{
                           inputProps: { 'aria-label': 'rows per page' },
                           native: true,
                       }}
                       onChangePage={handleChangePage}
                       onChangeRowsPerPage={handleChangeRowsPerPage}
                       ActionsComponent={TablePaginationActions}
                       />
                   </TableRow>
               </TableFooter>
           </Table>
   )
}

Thank you for your time and your answer!
Have a nice day
Louis

@cl4k cl4k added design: material This is about Material Design, please involve a visual or UX designer in the process status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 14, 2020
@oliviertassinari oliviertassinari added support: Stack Overflow Please ask the community on Stack Overflow and removed design: material This is about Material Design, please involve a visual or UX designer in the process status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 14, 2020
@support
Copy link

support bot commented Jul 14, 2020

👋 Thanks for using Material-UI!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://material-ui.com/getting-started/support/. Thanks!

If you have a question on StackOverflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@support support bot closed this as completed Jul 14, 2020
@ducthien1490
Copy link

Experienced same issue when using DateTimePicker
When pop-up opens , the page automatically scroll to top

@oliviertassinari
Copy link
Member

@ducthien1490 If you have a reprodution with the latest versions (alpha) please open a new issue about it with the link to the live reproduction, it will help, thanks.

@ducthien1490
Copy link

@oliviertassinari : I accidentially fixed it by set overflow: auto to body. I'll upgrade to alpha version soon and let you know if there're any further issue
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants