diff --git a/packages/react-table/src/docs/demos/Table.md b/packages/react-table/src/docs/demos/Table.md index e5dbdba7ce1..fd0d3918b17 100644 --- a/packages/react-table/src/docs/demos/Table.md +++ b/packages/react-table/src/docs/demos/Table.md @@ -2612,174 +2612,9 @@ class ComplexPaginationTableDemo extends React.Component { } ``` -### Pagination +### Static bottom pagination on mobile -```js -import React from 'react'; -import { - Checkbox, - Pagination, - Title, - Toolbar, - ToolbarContent, - ToolbarItem, - EmptyState, - EmptyStateIcon, - EmptyStateBody, - EmptyStateVariant, - Bullseye -} from '@patternfly/react-core'; -import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; -import globalDangerColor200 from '@patternfly/react-tokens/dist/esm/global_danger_color_200'; -import { Table, TableHeader, TableBody } from '@patternfly/react-table'; -import { Spinner } from '@patternfly/react-core'; - -class ComplexPaginationTableDemo extends React.Component { - constructor(props) { - super(props); - this.state = { - res: [], - perPage: 0, - total: 0, - page: 0, - error: null, - loading: true, - forceLoadingState: false - }; - - this.handleCheckboxChange = checked => { - console.log(checked); - this.setState({ forceLoadingState: checked }); - }; - } - - fetch(page, perPage) { - this.setState({ loading: true }); - fetch(`https://jsonplaceholder.typicode.com/posts?_page=${page}&_limit=${perPage}`) - .then(resp => resp.json()) - .then(resp => this.setState({ res: resp, perPage, page, loading: false, total: 100 })) - .catch(err => this.setState({ error: err, loading: false, perPage: 0, page: 0, total: 0 })); - } - - componentDidMount() { - this.fetch(this.state.page || 1, this.state.perPage || 20); - } - - renderPagination(variant = 'top') { - const { page, perPage, total } = this.state; - return ( - this.fetch(value, perPage)} - onPerPageSelect={(_evt, value) => this.fetch(1, value)} - variant={variant} - titles={{ - paginationTitle: `Pagination demo ${variant} pagination` - }} - /> - ); - } - - render() { - const { loading, res, error, forceLoadingState } = this.state; - - const toolbarItems = ( - - - - - - {this.renderPagination()} - - - ); - - if (error) { - const noResultsRows = [ - { - heightAuto: true, - cells: [ - { - props: { colSpan: 8 }, - title: ( - - - - - Check your connection and reload the page. - - - There was an error retrieving data. Check your connection and try again. - - - - ) - } - ] - } - ]; - - return ( - - - - -
-
- ); - } - - const loadingRows = [ - { - heightAuto: true, - cells: [ - { - props: { colSpan: 8 }, - title: ( - -
- -
-
- ) - } - ] - } - ]; - - return ( - - {toolbarItems} - {!(loading || forceLoadingState) && ( - [post.title, post.body])} - aria-label="Pagination Table Demo" - > - - -
- )} - {(loading || forceLoadingState) && ( - - - -
- )} -
- ); - } -} +```js isFullscreen file="table-demos/StaticBottomPagination.jsx" ``` ### Sticky header diff --git a/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx new file mode 100644 index 00000000000..40e8c3e2864 --- /dev/null +++ b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx @@ -0,0 +1,141 @@ +import React from 'react'; +import { + Button, + Card, + Toolbar, + ToolbarContent, + ToolbarGroup, + ToolbarItem, + Pagination, + Select, + SelectVariant, + SelectOption, + PageSection, + Label +} from '@patternfly/react-core'; +import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; +import { rows, columns } from '../../examples/Data.jsx'; + +import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon'; +import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper'; + +export const StaticBottomPagination = () => { + const [isSelectOpen, setIsSelectOpen] = React.useState(false); + const [page, setPage] = React.useState(1); + const [perPage, setPerPage] = React.useState(10); + const [paginatedRows, setPaginatedRows] = React.useState(rows.slice(0, 10)); + const handleSetPage = (_evt, newPage, perPage, startIdx, endIdx) => { + setPaginatedRows(rows.slice(startIdx, endIdx)); + setPage(newPage); + }; + handlePerPageSelect = (_evt, newPerPage, newPage, startIdx, endIdx) => { + setPaginatedRows(rows.slice(startIdx, endIdx)); + setPage(newPage); + setPerPage(newPerPage); + }; + + + const renderPagination = (variant, isCompact) => ( + + ); + + const renderLabel = labelText => { + switch (labelText) { + case 'Running': + return ; + case 'Stopped': + return ; + case 'Needs Maintenance': + return ; + case 'Down': + return ; + } + }; + + const tableToolbar = ( + + + + + + + + + + + {renderPagination('top', true)} + + + ); + + return ( + + + + + {tableToolbar} + + + + {columns.map((column, columnIndex) => ( + {column} + ))} + + + + {paginatedRows.map((row, rowIndex) => ( + + {row.name} + {row.threads} + {row.applications} + {row.workspaces} + {renderLabel(row.status)} + {row.location} + {row.lastModified} + + + {row.url} + + + + ))} + + + {renderPagination('bottom', false)} + + + + + ); +};