-
Notifications
You must be signed in to change notification settings - Fork 37
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
Pagination and activePage prop #60
Comments
Great question, @vlrmprjct! You can already control the component through its internal API like: import { useEffect, useRef } from 'react'
import SmartDataTable from 'react-smart-data-table'
import data from './data.json'
const getPageFromUrlPath = () => {
const url = new URL(window.location)
const urlParts = url.pathname.split('/')
const page = urlParts[urlParts.length - 1]
return page ? parseInt(page, 10) : 1
}
const App = () => {
const tableRef = useRef()
useEffect(() => {
if (tableRef?.current) {
tableRef.current.handleOnPageChange(null, { activePage: getPageFromUrlPath() })
}
}, [])
return (
<main>
<h1>App</h1>
<hr />
<SmartDataTable
name="test"
data={data}
perPage={10}
ref={tableRef}
/>
</main>
)
} |
Olá @joaocarmo, Thank You ! Nice ! |
Works pretty neat @joaocarmo , Thank You! 👍🏼 |
@vlrmprjct great to know it worked out well for you! Thanks for letting me know. I've added the information to the proper section in the documentation. |
Hello @joaocarmo ,
just my next question ...
I try to figure out how to set the table initially to a different page.
Lets say the route entry url looks like
../whatever/fancy/page/2
. Now I listen to anactivePage
param, here the2
.Is there a way to handle this ?
The text was updated successfully, but these errors were encountered: