({
data,
columns,
}: {
data: Person[]
columns: ColumnDef<Person>[]
})
| 82 | } |
| 83 | |
| 84 | function MyTable({ |
| 85 | data, |
| 86 | columns, |
| 87 | }: { |
| 88 | data: Person[] |
| 89 | columns: ColumnDef<Person>[] |
| 90 | }) { |
| 91 | const [pagination, setPagination] = React.useState<PaginationState>({ |
| 92 | pageIndex: 0, |
| 93 | pageSize: 10, |
| 94 | }) |
| 95 | |
| 96 | const table = useReactTable({ |
| 97 | columns, |
| 98 | data, |
| 99 | debugTable: true, |
| 100 | getCoreRowModel: getCoreRowModel(), |
| 101 | getSortedRowModel: getSortedRowModel(), |
| 102 | getFilteredRowModel: getFilteredRowModel(), |
| 103 | getPaginationRowModel: getPaginationRowModel(), |
| 104 | onPaginationChange: setPagination, |
| 105 | //no need to pass pageCount or rowCount with client-side pagination as it is calculated automatically |
| 106 | state: { |
| 107 | pagination, |
| 108 | }, |
| 109 | // autoResetPageIndex: false, // turn off page index reset when sorting or filtering |
| 110 | }) |
| 111 | |
| 112 | return ( |
| 113 | <div className="p-2"> |
| 114 | <div className="h-2" /> |
| 115 | <table> |
| 116 | <thead> |
| 117 | {table.getHeaderGroups().map(headerGroup => ( |
| 118 | <tr key={headerGroup.id}> |
| 119 | {headerGroup.headers.map(header => { |
| 120 | return ( |
| 121 | <th key={header.id} colSpan={header.colSpan}> |
| 122 | <div |
| 123 | {...{ |
| 124 | className: header.column.getCanSort() |
| 125 | ? 'cursor-pointer select-none' |
| 126 | : '', |
| 127 | onClick: header.column.getToggleSortingHandler(), |
| 128 | }} |
| 129 | > |
| 130 | {flexRender( |
| 131 | header.column.columnDef.header, |
| 132 | header.getContext() |
| 133 | )} |
| 134 | {{ |
| 135 | asc: ' 🔼', |
| 136 | desc: ' 🔽', |
| 137 | }[header.column.getIsSorted() as string] ?? null} |
| 138 | {header.column.getCanFilter() ? ( |
| 139 | <div> |
| 140 | <Filter column={header.column} table={table} /> |
| 141 | </div> |
nothing calls this directly
no test coverage detected
searching dependent graphs…