1.6.4 • Published 2 years ago
ts-paginator v1.6.4
ts-paginator

ts-paginatoris a TypeScript pagination hook for React or NextJS
Args
Instantiate the useTsPaginator hook with the following arguments:
| Args | Description | 
|---|---|
| totalRecordCount: number | The total count of records | 
| currentPage: number | The current page selection (zero indexed) | 
| rowsPerPage: 10(default10) | The current rows per page selection | 
UI/UX Functions
| Function | Description | Args | Return Type | Example Returns | 
|---|---|---|---|---|
| determinePaginationMessage | Calculates the pagination message | options?: { verb: 'Showing' OR 'Displaying', noun?: string, hideMessageOnZeroRecords: boolean } | string | Displaying 1 to 10 of 20 records | 
| determineRowsPerPageOptions | Calculates the rows per page options | number[] | [10] | |
| determinePaginationPages | Calculates the pagination pages and uses 0as a range placeholder for page ranges greater than three | number[] | [1, 2] | |
| determinePaginationDisabledState | Can be used to disable the previous page or next page button | boolean | true | 
State Altering Functions
| Function | Description | Args | Return Type | 
|---|---|---|---|
| handleChangeTotalRecordCount | Changes the total record count | newTotalRecordCount: number | void | 
| handleChangeRowsPerPage | Changes the rows per page | newRowsPerPage: number | void | 
| handleChangePage | Changes the current page | newPage: number | void | 
Extra Functions
Not required to build working pagination, but might be useful. Coming soon.
Usage
npm i --save ts-paginator
import useTsPaginator from 'ts-paginator';
function MyComponent() {
  const {
    totalRecordCount,
    rowsPerPage,
    currentPage,
    _determinePaginationMessage,
    _determinePaginationDisabledState,
    _determinePaginationPages,
    _determineRowsPerPageOptions,
    _handleChangeTotalRecordCount,
    _handleChangeRowsPerPage,
    _handleChangePage,
  } = useTsPaginator(20, 0);
  const message = _determinePaginationMessage({ verb: 'Showing', noun: 'entries' }); // Showing 1 to 10 of 20 entries
  return <p>{message}</p>;
}Release Notes
1.6.0 
- Adressed a shortcoming in _determinePaginationMessagenot properly handling atotalRecordCountof0
- Added an optional nounkey to the_determinePaginationMessageoptionsparameter
- Added an optional hideMessageOnZeroRecordskey to the_determinePaginationMessageoptionsparameter which, if set, returns the message as an empty string
Example
https://github.com/WNortier/ts-paginator-example

1.6.4
2 years ago
1.6.3
2 years ago
1.6.2
2 years ago
1.6.1
2 years ago
1.6.0
2 years ago
1.5.1
3 years ago
1.5.0
3 years ago
1.4.9
3 years ago
1.4.8
3 years ago
1.4.7
3 years ago
1.4.6
3 years ago
1.4.5
3 years ago
1.4.4
3 years ago
1.4.3
3 years ago
1.4.2
3 years ago
1.4.1
3 years ago
1.4.0
3 years ago
1.3.19
3 years ago
1.3.18
3 years ago
1.12.18
3 years ago
1.12.17
3 years ago
1.2.16
3 years ago
1.2.15
3 years ago
1.2.14
3 years ago
1.2.13
3 years ago
1.2.12
3 years ago
1.2.11
3 years ago
1.2.10
3 years ago
1.1.10
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago