Skip to content

Commit 49acf7d

Browse files
authored
chore(table): add option to show total pages (#420)
1 parent 4578f3b commit 49acf7d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/components/table/table.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export function Table({
8585
autoResetFilters = false,
8686
autoResetExpanded = false,
8787
withPagination = false,
88+
showTotalPages = false,
8889
controlledState = {},
8990
renderGroupHead,
9091
initialState = {},
@@ -103,10 +104,10 @@ export function Table({
103104
...customProps
104105
}) {
105106
// preserve column order to override default grouping behaviour
106-
const columnOrder = useMemo(() => controlledState.columnOrder || columns.map(({ id }) => id), [
107-
columns,
108-
controlledState.columnOrder,
109-
])
107+
const columnOrder = useMemo(
108+
() => controlledState.columnOrder || columns.map(({ id }) => id),
109+
[columns, controlledState.columnOrder]
110+
)
110111

111112
const reactTableHooks = layoutType === "block" ? blockTableHooks : tableHooks
112113

@@ -182,11 +183,10 @@ export function Table({
182183
return rows
183184
}, [groupBy, groupsOrderSettings, rows])
184185

185-
const tableRows = useMemo(() => (withPagination ? page : orderedRows), [
186-
withPagination,
187-
page,
188-
orderedRows,
189-
])
186+
const tableRows = useMemo(
187+
() => (withPagination ? page : orderedRows),
188+
[withPagination, page, orderedRows]
189+
)
190190

191191
const showPagination = withPagination && pageCount > 1
192192
const goToPreviousPage = useCallback(() => {
@@ -263,7 +263,10 @@ export function Table({
263263
disabled={!canPreviousPage}
264264
onClick={goToPreviousPage}
265265
/>
266-
<Text color="textDescription">{pageIndex + 1}</Text>
266+
<Text color="textDescription">
267+
{pageIndex + 1}
268+
{showTotalPages && ` / ${pageCount}`}
269+
</Text>
267270
<Icon
268271
name="chevron_left"
269272
color="text"

0 commit comments

Comments
 (0)