|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { ThemeProvider } from 'styled-components'; |
3 | | -import { tableReducer } from './tableReducer'; |
| 3 | +import useColumns from '../hooks/useColumns'; |
| 4 | +import useDidUpdateEffect from '../hooks/useDidUpdateEffect'; |
| 5 | +import { CellBase } from './Cell'; |
| 6 | +import NoData from './NoDataWrapper'; |
| 7 | +import NativePagination from './Pagination'; |
| 8 | +import ProgressWrapper from './ProgressWrapper'; |
| 9 | +import ResponsiveWrapper from './ResponsiveWrapper'; |
4 | 10 | import Table from './Table'; |
5 | | -import Head from './TableHead'; |
6 | | -import HeadRow from './TableHeadRow'; |
7 | | -import Row from './TableRow'; |
| 11 | +import Body from './TableBody'; |
8 | 12 | import Column from './TableCol'; |
9 | 13 | import ColumnCheckbox from './TableColCheckbox'; |
| 14 | +import ColumnExpander from './TableColExpander'; |
| 15 | +import Foot from './TableFoot'; |
| 16 | +import FootRow from './TableFootRow'; |
| 17 | +import TableFooterCell from './TableFooterCell'; |
| 18 | +import Head from './TableHead'; |
| 19 | +import HeadRow from './TableHeadRow'; |
10 | 20 | import Header from './TableHeader'; |
| 21 | +import Row from './TableRow'; |
11 | 22 | import Subheader from './TableSubheader'; |
12 | | -import Body from './TableBody'; |
13 | | -import ResponsiveWrapper from './ResponsiveWrapper'; |
14 | | -import ProgressWrapper from './ProgressWrapper'; |
15 | 23 | import Wrapper from './TableWrapper'; |
16 | | -import ColumnExpander from './TableColExpander'; |
17 | | -import { CellBase } from './Cell'; |
18 | | -import NoData from './NoDataWrapper'; |
19 | | -import NativePagination from './Pagination'; |
20 | | -import useDidUpdateEffect from '../hooks/useDidUpdateEffect'; |
21 | | -import { prop, getNumberOfPages, sort, isEmpty, isRowSelected, recalculatePage } from './util'; |
22 | 24 | import { defaultProps } from './defaultProps'; |
23 | 25 | import { createStyles } from './styles'; |
| 26 | +import { tableReducer } from './tableReducer'; |
24 | 27 | import { |
25 | 28 | Action, |
26 | 29 | AllRowsAction, |
27 | 30 | SingleRowAction, |
28 | | - TableRow, |
29 | 31 | SortAction, |
| 32 | + SortOrder, |
30 | 33 | TableProps, |
| 34 | + TableRow, |
31 | 35 | TableState, |
32 | | - SortOrder, |
33 | 36 | } from './types'; |
34 | | -import useColumns from '../hooks/useColumns'; |
| 37 | +import { getNumberOfPages, isEmpty, isRowSelected, prop, recalculatePage, sort } from './util'; |
| 38 | +import { STOP_PROP_TAG } from './constants'; |
35 | 39 |
|
36 | 40 | function DataTable<T>(props: TableProps<T>): JSX.Element { |
37 | 41 | const { |
@@ -81,6 +85,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element { |
81 | 85 | noHeader = defaultProps.noHeader, |
82 | 86 | fixedHeader = defaultProps.fixedHeader, |
83 | 87 | fixedHeaderScrollHeight = defaultProps.fixedHeaderScrollHeight, |
| 88 | + showFooter = defaultProps.showFooter, |
84 | 89 | pagination = defaultProps.pagination, |
85 | 90 | subHeader = defaultProps.subHeader, |
86 | 91 | subHeaderAlign = defaultProps.subHeaderAlign, |
@@ -280,6 +285,14 @@ function DataTable<T>(props: TableProps<T>): JSX.Element { |
280 | 285 | return false; |
281 | 286 | }; |
282 | 287 |
|
| 288 | + const showTableFoot = () => { |
| 289 | + if (!showFooter) { |
| 290 | + return false; |
| 291 | + } |
| 292 | + |
| 293 | + return sortedData.length > 0 && !progressPending; |
| 294 | + }; |
| 295 | + |
283 | 296 | // recalculate the pagination and currentPage if the rows length changes |
284 | 297 | if (pagination && !paginationServer && sortedData.length > 0 && tableRows.length === 0) { |
285 | 298 | const updatedPage = getNumberOfPages(sortedData.length, rowsPerPage); |
@@ -489,6 +502,30 @@ function DataTable<T>(props: TableProps<T>): JSX.Element { |
489 | 502 | })} |
490 | 503 | </Body> |
491 | 504 | )} |
| 505 | + |
| 506 | + {showTableFoot() && ( |
| 507 | + <Foot className="rdt_TableFoot" role="rowgroup"> |
| 508 | + <FootRow className="rdt_TableFootRow" role="row" $dense={dense}> |
| 509 | + {selectableRows && <CellBase style={{ flex: '0 0 48px' }} />} |
| 510 | + {showFooter && |
| 511 | + tableColumns.map(column => ( |
| 512 | + <TableFooterCell<T> |
| 513 | + id={column.id as string} |
| 514 | + key={column.id} |
| 515 | + dataTag={column.ignoreRowClick || column.button ? null : STOP_PROP_TAG} |
| 516 | + column={column} |
| 517 | + rows={tableRows} |
| 518 | + isDragging={false} |
| 519 | + onDragStart={handleDragStart} |
| 520 | + onDragOver={handleDragOver} |
| 521 | + onDragEnd={handleDragEnd} |
| 522 | + onDragEnter={handleDragEnter} |
| 523 | + onDragLeave={handleDragLeave} |
| 524 | + /> |
| 525 | + ))} |
| 526 | + </FootRow> |
| 527 | + </Foot> |
| 528 | + )} |
492 | 529 | </Table> |
493 | 530 | </Wrapper> |
494 | 531 | </ResponsiveWrapper> |
|
0 commit comments