MCPcopy Create free account
hub / github.com/Codehagen/Badget / DataTable

Function DataTable

src/components/data-table.tsx:339–628  ·  view source on GitHub ↗
({
  data: initialData,
}: {
  data: z.infer<typeof schema>[]
})

Source from the content-addressed store, hash-verified

337}
338
339export function DataTable({
340 data: initialData,
341}: {
342 data: z.infer<typeof schema>[]
343}) {
344 const [data, setData] = React.useState(() => initialData)
345 const [rowSelection, setRowSelection] = React.useState({})
346 const [columnVisibility, setColumnVisibility] =
347 React.useState<VisibilityState>({})
348 const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
349 []
350 )
351 const [sorting, setSorting] = React.useState<SortingState>([])
352 const [pagination, setPagination] = React.useState({
353 pageIndex: 0,
354 pageSize: 10,
355 })
356 const sortableId = React.useId()
357 const sensors = useSensors(
358 useSensor(MouseSensor, {}),
359 useSensor(TouchSensor, {}),
360 useSensor(KeyboardSensor, {})
361 )
362
363 const dataIds = React.useMemo<UniqueIdentifier[]>(
364 () => data?.map(({ id }) => id) || [],
365 [data]
366 )
367
368 const table = useReactTable({
369 data,
370 columns,
371 state: {
372 sorting,
373 columnVisibility,
374 rowSelection,
375 columnFilters,
376 pagination,
377 },
378 getRowId: (row) => row.id.toString(),
379 enableRowSelection: true,
380 onRowSelectionChange: setRowSelection,
381 onSortingChange: setSorting,
382 onColumnFiltersChange: setColumnFilters,
383 onColumnVisibilityChange: setColumnVisibility,
384 onPaginationChange: setPagination,
385 getCoreRowModel: getCoreRowModel(),
386 getFilteredRowModel: getFilteredRowModel(),
387 getPaginationRowModel: getPaginationRowModel(),
388 getSortedRowModel: getSortedRowModel(),
389 getFacetedRowModel: getFacetedRowModel(),
390 getFacetedUniqueValues: getFacetedUniqueValues(),
391 })
392
393 function handleDragEnd(event: DragEndEvent) {
394 const { active, over } = event
395 if (active && over && active.id !== over.id) {
396 setData((data) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected