11# React Final Table <!-- omit in toc -->
22
3- ![ CI] ( https://github.com/Buuntu/react-final-table/workflows/tests/badge.svg ) [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-green.svg )] ( https://opensource.org/licenses/MIT ) [ ![ codecov] ( https://codecov.io/gh/Buuntu/react-final-table/branch/master/graph/badge.svg )] ( https://codecov.io/gh/Buuntu/react-final-table ) ![ minzipped-size] ( https://img.shields.io/bundlephobia/minzip/react-final-table ) ![ release] ( https://img.shields.io/npm/v/react-final-table ) [ ![ semantic-release] ( https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg )] ( https://github.com/semantic-release/semantic-release )
3+ ![ CI] ( https://github.com/Buuntu/react-final-table/workflows/tests/badge.svg )
4+ [ ![ License:
5+ MIT] ( https://img.shields.io/badge/License-MIT-green.svg )] ( https://opensource.org/licenses/MIT )
6+ [ ![ codecov] ( https://codecov.io/gh/Buuntu/react-final-table/branch/master/graph/badge.svg )] ( https://codecov.io/gh/Buuntu/react-final-table )
7+ ![ minzipped-size] ( https://img.shields.io/bundlephobia/minzip/react-final-table )
8+ ![ release] ( https://img.shields.io/npm/v/react-final-table )
9+ [ ![ semantic-release] ( https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg )] ( https://github.com/semantic-release/semantic-release )
410
511A [ headless UI component
612libray] ( https://www.merrickchristensen.com/articles/headless-user-interface-components/ )
713for managing complex table state in React.
814
9- Inspired by
10- [ react-table] ( https://github.com/tannerlinsley/react-table ) but with Typescript
11- support built in and a simpler API.
15+ Inspired by [ react-table] ( https://github.com/tannerlinsley/react-table ) but with
16+ Typescript support built in and a simpler API.
1217
1318## Features
1419
@@ -32,16 +37,17 @@ support built in and a simpler API.
3237 - [ Basic example] ( #basic-example )
3338 - [ Searching] ( #searching )
3439 - [ Row Selection] ( #row-selection )
40+ - [ Pagination] ( #pagination )
3541- [ Performance] ( #performance )
3642- [ Contributing] ( #contributing )
3743
3844## Motivation
3945
40- While there is an abundance of table libraries out there to help with sorting, filtering, pagination, and more, most are opinionated
41- about the user interface. Opinionated UIs can seem nice at first, but they
42- quickly become limiting. To embrace the Unix philosphy of separation of
43- concerns, the interface should be separate from the engine (from [ The Art of
44- Unix
46+ While there is an abundance of table libraries out there to help with sorting,
47+ filtering, pagination, and more, most are opinionated about the user interface.
48+ Opinionated UIs can seem nice at first, but they quickly become limiting. To
49+ embrace the Unix philosphy of separation of concerns, the interface should be
50+ separate from the engine (from [ The Art of Unix
4551Programming] ( https://www.goodreads.com/book/show/104745.The_Art_of_UNIX_Programming ) ).
4652
4753This is a minimal, type-safe, headless UI component library that you can plugin
@@ -71,7 +77,9 @@ any table functionality. Only `columns` and `rows` are required as arguments:
7177const { headers , rows } = useTable (columns, rows);
7278```
7379
74- 1 . ` columns ` : The first argument is an array of columns of type ColumnType. Only the name of each column is required. Each column has the following type signature:
80+ 1 . ` columns ` : The first argument is an array of columns of type ColumnType. Only
81+ the name of each column is required. Each column has the following type
82+ signature:
7583
7684``` typescript
7785type ColumnType <T > = {
@@ -84,7 +92,8 @@ type ColumnType<T> = {
8492};
8593```
8694
87- 2 . ` rows ` : Rows is the second argument to useTable and can be an array of any _ object_ type.
95+ 2 . ` rows ` : Rows is the second argument to useTable and can be an array of any
96+ _ object_ type.
8897
8998## Examples
9099
@@ -233,8 +242,57 @@ function App() {
233242 < / >
234243 );
235244}
245+ ` ` `
246+
247+ ### Pagination
248+
249+ ` ` ` jsx
250+ export const App: FC = () => {
251+ const memoColumns = useMemo (() => columns, []);
252+ const memoData = useMemo (() => data, []);
236253
237- export default App ;
254+ const { headers , rows , pagination } = useTable< {
255+ firstName: string;
256+ lastName: string;
257+ }> (memoColumns, memoData, { pagination: true });
258+
259+ return (
260+ <>
261+ < table>
262+ < thead>
263+ < tr>
264+ {headers .map ((header , idx ) => (
265+ < th key= {idx}> {header .render ()}< / th>
266+ ))}
267+ < / tr>
268+ < / thead>
269+ < tbody>
270+ {rows .map ((row , idx ) => (
271+ < tr key= {idx}>
272+ {row .cells .map ((cell , idx ) => (
273+ < td key= {idx}> {cell .render ()}< / td>
274+ ))}
275+ < / tr>
276+ ))}
277+ < / tbody>
278+ < / table>
279+ < div>
280+ < button
281+ disabled= {pagination .canPrev }
282+ onClick= {() => pagination .prevPage ()}
283+ >
284+ {' <' }
285+ < / button>
286+ < button
287+ disabled= {pagination .canNext }
288+ onClick= {() => pagination .nextPage ()}
289+ >
290+ {' >' }
291+ < / button>
292+ < / div>
293+ < / >
294+ );
295+ }
238296` ` `
239297
240298## Performance
0 commit comments