Customizing the Lightning Datatable is quite easy with Salesforce. Here is a simple and sample code with with 3 pages, getting data dynamically for every pagination and selectable rows with memory on every page.
Link to the code repository: https://github.com/VijayaSankarN/Lightning-Datatable-with-Pagination
You can find two variables
currentSelectedRows (to hold the selected items in the current page) and
overallSelectedRows (to hold all the selected items) in the Lightning Component.
For now, the data is fetched from the helper using
setData method, however, apex call can also be initiated to fetch the records dynamically.