Skip to content

Commit bc8ac94

Browse files
authored
Make pagination query param configurable (#256)
1 parent 5469907 commit bc8ac94

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/npm-fastui-bootstrap/src/pagination.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ interface Link {
77
locked?: boolean
88
active?: boolean
99
page?: number
10+
pageQueryParam?: string
1011
}
1112

1213
export const Pagination: FC<models.Pagination> = (props) => {
13-
const { page, pageCount } = props
14-
14+
const { page, pageCount, pageQueryParam } = props
1515
if (pageCount === 1) return null
1616

1717
const links: Link[] = [
@@ -20,17 +20,19 @@ export const Pagination: FC<models.Pagination> = (props) => {
2020
ariaLabel: 'Previous',
2121
locked: page === 1,
2222
page: page - 1,
23+
pageQueryParam,
2324
},
2425
{
2526
Display: () => <>1</>,
2627
locked: page === 1,
2728
active: page === 1,
2829
page: 1,
30+
pageQueryParam,
2931
},
3032
]
3133

3234
if (page > 4) {
33-
links.push({ Display: () => <>...</> })
35+
links.push({ Display: () => <>...</>, pageQueryParam })
3436
}
3537

3638
for (let p = page - 2; p <= page + 2; p++) {
@@ -40,24 +42,27 @@ export const Pagination: FC<models.Pagination> = (props) => {
4042
locked: page === p,
4143
active: page === p,
4244
page: p,
45+
pageQueryParam,
4346
})
4447
}
4548

4649
if (page < pageCount - 3) {
47-
links.push({ Display: () => <>...</> })
50+
links.push({ Display: () => <>...</>, pageQueryParam })
4851
}
4952

5053
links.push({
5154
Display: () => <>{pageCount}</>,
5255
locked: page === pageCount,
5356
page: pageCount,
57+
pageQueryParam,
5458
})
5559

5660
links.push({
5761
Display: () => <span aria-hidden="true">&raquo;</span>,
5862
ariaLabel: 'Next',
5963
locked: page === pageCount,
6064
page: page + 1,
65+
pageQueryParam,
6166
})
6267

6368
return (
@@ -71,7 +76,7 @@ export const Pagination: FC<models.Pagination> = (props) => {
7176
)
7277
}
7378

74-
const PaginationLink: FC<Link> = ({ Display, ariaLabel, locked, active, page }) => {
79+
const PaginationLink: FC<Link> = ({ Display, ariaLabel, locked, active, page, pageQueryParam }) => {
7580
if (!page) {
7681
return (
7782
<li className="page-item">
@@ -82,7 +87,10 @@ const PaginationLink: FC<Link> = ({ Display, ariaLabel, locked, active, page })
8287
)
8388
}
8489
const className = renderClassName({ 'page-link': true, disabled: locked && !active, active } as models.ClassName)
85-
const onClick: models.GoToEvent = { type: 'go-to', query: { page } }
90+
const onClick: models.GoToEvent = {
91+
type: 'go-to',
92+
query: { [pageQueryParam !== undefined ? pageQueryParam : 'page']: page },
93+
}
8694
return (
8795
<li className="page-item">
8896
<components.LinkRender onClick={onClick} className={className} locked={locked || active} ariaLabel={ariaLabel}>

src/npm-fastui/src/models.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ export interface Pagination {
301301
total: number
302302
className?: ClassName
303303
type: 'Pagination'
304+
pageQueryParam?: string
304305
pageCount: number
305306
}
306307
/**

src/python-fastui/fastui/components/tables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Pagination(pydantic.BaseModel):
5959
total: int
6060
class_name: _class_name.ClassNameField = None
6161
type: _t.Literal['Pagination'] = 'Pagination'
62+
page_query_param: str = pydantic.Field('page', serialization_alias='pageQueryParam')
6263

6364
@pydantic.computed_field(alias='pageCount')
6465
def page_count(self) -> int:

0 commit comments

Comments
 (0)