MCPcopy Index your code
hub / github.com/TanStack/table / MyTable

Function MyTable

examples/react/pagination/src/main.tsx:84–240  ·  view source on GitHub ↗
({
  data,
  columns,
}: {
  data: Person[]
  columns: ColumnDef<Person>[]
})

Source from the content-addressed store, hash-verified

82}
83
84function 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>

Callers

nothing calls this directly

Calls 9

useReactTableFunction · 0.90
flexRenderFunction · 0.90
getCoreRowModelFunction · 0.85
getSortedRowModelFunction · 0.85
getFilteredRowModelFunction · 0.85
getPaginationRowModelFunction · 0.85
getContextMethod · 0.80
previousPageMethod · 0.80
nextPageMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…