简体   繁体   中英

antd table scroll up on pagination click

this is my table code in AntD, On pagination clicked I want it to scroll to page top. I tried using BackTop but I couldn't figure out how to do that with pagination

const GenericTable = props => {
const { withHeader, pagination, showTable, error } = props;
return (
  <Fragment>
    {withHeader && <TableHeader {...props} />}
     {showTable && (
      <CustomTable
        {...props}
        pagination={{
          ...pagination,
          showTotal,
        }}
      />
    )}
    <TableFooter>{<Error>{error}</Error>}</TableFooter>
  </Fragment>
);
};
GenericTable.defaultProps = {
 pagination: {
 pageSize: 10,
 },
};

Antd's table have a onChange method, by using that you can scroll to top by java script.

use

document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0;

CodeSanbox Link Antd's table scroll top on pagination

You can always store pagination in state and compare it to latest one, to avoid scroll of table on changing of anything else in table like filter or sorting.

I hope this would help.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM