|
| 1 | +# TableAdapter |
| 2 | + |
| 3 | +A powerful, flexible, and feature-rich React table component built on top of [TanStack Table (React Table v8)](https://tanstack.com/table/v8). Designed for both client-side and server-side data, TableAdapter provides advanced features like pagination, sorting, filtering, row selection, column resizing, and more, with a simple and customizable API. |
| 4 | + |
| 5 | +[](./LICENSE) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Client-side & server-side** pagination, sorting, filtering, and grouping |
| 12 | +- **Row selection**, expansion, pinning, and grouping |
| 13 | +- **Column resizing**, ordering, and visibility toggles |
| 14 | +- **Custom renderers** for headers, footers, cells, pagination, and more |
| 15 | +- **Loading states** and customizable loading components |
| 16 | +- **Accessibility**: ARIA labels and keyboard navigation |
| 17 | +- **TypeScript** support with strong generics |
| 18 | +- **Export to CSV** utility |
| 19 | +- **Tailwind CSS**-friendly by default |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +```bash |
| 26 | +npm install @TechFusionMasters/tanstack-table-adapter |
| 27 | +``` |
| 28 | + |
| 29 | +Or with yarn: |
| 30 | + |
| 31 | +```bash |
| 32 | +yarn add @TechFusionMasters/tanstack-table-adapter |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```tsx |
| 40 | +import React from "react"; |
| 41 | +import { TableAdapter } from "@TechFusionMasters/tanstack-table-adapter"; |
| 42 | + |
| 43 | +const columns = [ |
| 44 | + { accessorKey: "id", header: "ID" }, |
| 45 | + { accessorKey: "name", header: "Name" }, |
| 46 | + { accessorKey: "age", header: "Age" }, |
| 47 | +]; |
| 48 | + |
| 49 | +const data = [ |
| 50 | + { id: 1, name: "Alice", age: 25 }, |
| 51 | + { id: 2, name: "Bob", age: 30 }, |
| 52 | + { id: 3, name: "Charlie", age: 22 }, |
| 53 | +]; |
| 54 | + |
| 55 | +export default function App() { |
| 56 | + return ( |
| 57 | + <TableAdapter |
| 58 | + data={data} |
| 59 | + columns={columns} |
| 60 | + enablePagination |
| 61 | + enableSorting |
| 62 | + className="w-full max-w-2xl" |
| 63 | + /> |
| 64 | + ); |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## API |
| 71 | + |
| 72 | +### `<TableAdapter />` Props |
| 73 | + |
| 74 | +#### Core |
| 75 | + |
| 76 | +- `data`: Array of row objects |
| 77 | +- `columns`: Array of column definitions ([TanStack Table ColumnDef](https://tanstack.com/table/v8/docs/api/core/column-def)) |
| 78 | +- `totalRowCount?`: For server-side pagination |
| 79 | +- `id?`, `debugTable?`, `getRowId?` |
| 80 | + |
| 81 | +#### Features |
| 82 | + |
| 83 | +- `enablePagination?`, `enableSorting?`, `enableMultiSort?`, `enableColumnFilters?`, `enableGlobalFilter?`, `enableColumnResizing?`, `enableRowSelection?`, `enableExpanding?`, `enablePinning?`, `enableStickyHeader?`, `enableGrouping?` |
| 84 | + |
| 85 | +#### State & Control |
| 86 | + |
| 87 | +- `pageSize?`, `pageIndex?`, `sorting?`, `columnFilters?`, `globalFilter?`, `columnVisibility?`, `rowSelection?`, `expanded?`, `columnOrder?`, `columnPinning?`, `grouping?` |
| 88 | +- `onPaginationChange?`, `onSortingChange?`, `onColumnFiltersChange?`, `onGlobalFilterChange?`, `onColumnVisibilityChange?`, `onRowSelectionChange?`, `onExpandedChange?`, `onColumnOrderChange?`, `onColumnPinningChange?`, `onGroupingChange?` |
| 89 | + |
| 90 | +#### Advanced |
| 91 | + |
| 92 | +- `manualPagination?`, `manualSorting?`, `manualFiltering?`, `manualGrouping?`, `pageCount?`, `autoResetPageIndex?`, `globalFilterFn?` |
| 93 | + |
| 94 | +#### Custom Renderers |
| 95 | + |
| 96 | +- `renderTableHeader?`, `renderTableFooter?`, `renderPagination?`, `renderNoResults?`, `renderExpanded?`, `renderRowSubComponent?`, `renderGroupedCell?`, `renderSortIcon?` |
| 97 | + |
| 98 | +#### Events |
| 99 | + |
| 100 | +- `onRowClick?`, `onCellClick?`, `onExportData?` |
| 101 | + |
| 102 | +#### Loading & Accessibility |
| 103 | + |
| 104 | +- `isLoading?`, `isPaginationLoading?`, `loadingComponent?`, `paginationLoadingComponent?`, `showOverlayLoading?` |
| 105 | +- `ariaLabel?`, `ariaLabelledBy?`, `ariaDescribedBy?` |
| 106 | + |
| 107 | +#### Styling |
| 108 | + |
| 109 | +- `className?`, `tableClassName?`, `headerClassName?`, `bodyClassName?`, `rowClassName?`, `cellClassName?`, `columnResizeMode?`, `pageSizeOptions?`, `enableSortingRemoval?` |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## Utilities & Helpers |
| 114 | + |
| 115 | +- `exportToCSV(data, columns, filename?)`: Export table data to CSV |
| 116 | +- `fuzzyFilter`: Fuzzy text filter function for global/column filtering |
| 117 | +- `GlobalFilterInput`: Ready-to-use global filter input component |
| 118 | +- `ColumnVisibilityToggle`: UI for toggling column visibility |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Customization |
| 123 | + |
| 124 | +- **Custom loading, pagination, and no-results components** can be provided via props |
| 125 | +- **Full control** over table state (controlled/uncontrolled) |
| 126 | +- **Composable** with your own UI and TanStack Table plugins |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## License |
| 131 | + |
| 132 | +MIT © 2025 TechFusionMasters |
0 commit comments