MCPcopy
hub / github.com/TanStack/table / App

Function App

examples/react/column-ordering/src/main.tsx:68–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66]
67
68function App() {
69 const [data, setData] = React.useState(() => makeData(20))
70 const [columns] = React.useState(() => [...defaultColumns])
71
72 const [columnVisibility, setColumnVisibility] = React.useState({})
73 const [columnOrder, setColumnOrder] = React.useState<ColumnOrderState>([])
74
75 const rerender = () => setData(() => makeData(20))
76
77 const table = useReactTable({
78 data,
79 columns,
80 state: {
81 columnVisibility,
82 columnOrder,
83 },
84 onColumnVisibilityChange: setColumnVisibility,
85 onColumnOrderChange: setColumnOrder,
86 getCoreRowModel: getCoreRowModel(),
87 debugTable: true,
88 debugHeaders: true,
89 debugColumns: true,
90 })
91
92 const randomizeColumns = () => {
93 table.setColumnOrder(
94 faker.helpers.shuffle(table.getAllLeafColumns().map(d => d.id))
95 )
96 }
97
98 return (
99 <div className="p-2">
100 <div className="inline-block border border-black shadow rounded">
101 <div className="px-1 border-b border-black">
102 <label>
103 <input
104 {...{
105 type: 'checkbox',
106 checked: table.getIsAllColumnsVisible(),
107 onChange: table.getToggleAllColumnsVisibilityHandler(),
108 }}
109 />{' '}
110 Toggle All
111 </label>
112 </div>
113 {table.getAllLeafColumns().map(column => {
114 return (
115 <div key={column.id} className="px-1">
116 <label>
117 <input
118 {...{
119 type: 'checkbox',
120 checked: column.getIsVisible(),
121 onChange: column.getToggleVisibilityHandler(),
122 }}
123 />{' '}
124 {column.id}
125 </label>

Callers

nothing calls this directly

Calls 7

makeDataFunction · 0.90
useReactTableFunction · 0.90
flexRenderFunction · 0.90
getCoreRowModelFunction · 0.85
getContextMethod · 0.80
rerenderFunction · 0.70
randomizeColumnsFunction · 0.70

Tested by

no test coverage detected