1.1.0 • Published 3 years ago

@pmwcs/data-table-pagination v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

Data Table Pagination (PMWCS Addon)

Pagination for data tables.

  • Module @pmwcs/data-table-pagination
  • Import styles:
    • Using CSS Loader
      • import '@pmwcs/data-table-pagination/styles';
    • Or include stylesheets
      • '@pmwcs/data-table-pagination/data-table-pagination.css'
      • '@pmwcs/icon-button/styles'
      • '@pmwcs/select/styles'

Uncontrolled

<DataTablePagination
  defaultPage={1}
  count={12}
  onChangePage={(evt, page) => {}}
  onChangeRowsPerPage={(evt, rowsPerPage) => {}}
/>

Controlled

function Controlled ({ page: page_, count = 55 }) {
  const [page, setPage] = useState(page_)
  const rowsPerPageOptions = [
    10, 25, { value: -1, label: 'Todas' }
  ]
  const [rowsPerPage, setRowsPerPage] = useState(rowsPerPageOptions[0])

  return (
    <DataTablePagination
      count={count}
      page={page}
      rowsPerPage={rowsPerPage}
      rowsPerPageOptions={rowsPerPageOptions}
      onChangePage={(_, page) => setPage(page)}
      onChangeRowsPerPage={(_, rowsPerPage) => setRowsPerPage(rowsPerPage)}
      labelRowsPerPage='Filas por página'
      labelDisplayedRows={({ from, to, count }) => `del ${from} a ${to} ${count === -1 ? '' : `de ${count}`}`}
    />
  )
}

DataTablePagination

The DataTablePagination Component.

Props

NameTypeDescription
countnumberThe total number of rows. To enable server side pagination for an unknown number of items, provide -1.
pagenumberThe zero-based index of the current page.
rowsPerPagenumberThe number of rows per page.
rowsPerPageOptionsArray<number \| { value: number; label: string }>Customizes the options of the rows per page select field. If one option is available, no select field will be displayed. [10, 50, { value: -1, label: 'All' }] the value and label keys will be used respectively for the value and label of the option. default is [10, 25, 50, 100]
onChangePage(event: Event) => voidCallback fired when the page is changed.
onChangeRowsPerPage(event: Event) => voidCallback fired when the number of rows per page is changed.
labelRowsPerPageAnyComponentLabel for rows per page. Default 'Rows per page:'
labelDisplayedRows({ from, to, count }) => stringCustomize the displayed rows label. Default ({ from, to, count }) => ${from}-${to} of ${count !== -1 ? count : more than ${to}}