Filigran

Datatable Example

Translate in French
1 - 50 / 500
First name
lastName
Age
Visits
Status
Description
Profile Progress
JudithDaugherty25825single67
CecileKohler30101complicated51
IrisLarson246single88
ManuelBrekke13595complicated4
JasperAnkunding14169relationship88
AntonetteHilpert0394relationship87
RosalieGrimes32679single81
MarcellaQuitzon38912relationship57
AlonzoFunk31629relationship73
MeggieSchaefer22955relationship10
JuliusKertzmann5635relationship100
KyleeLowe33977relationship39
StephanieBailey12736complicated84
RebeccaDach15254complicated69
YvetteDoyle14561single56
ArchFrami14679complicated54
RuthieShields254complicated92
DavinJacobi22796single80
LueHomenick20115complicated22
RudolphSchowalter17471relationship9
JoycePollich6156single94
JeanSchmeler8491single79
TamiaBeier39680relationship88
MayAbshire1151single42
HerthaReinger13480complicated8
RhiannaBeer30352single4
JudyRath25695relationship74
RufusUpton24830single5
KarsonGottlieb3483relationship74
JeraldSpencer5194single70
KoreyPowlowski8959complicated56
AlfMohr24215single28
ElviraKiehn0546single25
MelanieUllrich465complicated80
MichealKonopelski2848complicated5
DeonteLabadie15828complicated69
DarnellUllrich27347relationship51
TheresaLind-Wisoky8131complicated12
ZakaryKuhic39552relationship19
TrevorSchinner5442complicated83
JaydeLemke18842complicated85
KayleighHills27325complicated60
DarienHuel29620relationship85
TravisEmmerich3182single24
DomenicaHartmann-Reichert18903relationship72
LatoyaPfannerstill35292complicated87
ElmorePaucek39805single59
ViolaKutch27561relationship99
OceaneMitchell2688single72
LadariusWehner22127single62
Selected
{ "selectAll": false, "selectedIds": [], "excludedIds": [] }

How to use this separator

Props

NameTypeDefaultDescription
dataMyCustomType[]-The data displayed in the tab.
columns<ColumnDef<MyCustomType>[]>-The name of the colomns, how to get it, actions on column...
isLoadingboolean-Displays a skeleton on rows while loading.
tableOptions{onRowSelectionChange, getSortedRowModel, getPaginationRowModel, onPaginationChange, enableRowSelection, onColumnOrderChange }-Change the default rendered element for the one passed as a child, merging their props and behavior.
tableState{columnVisibility, columnOrder: string[], columnPinning:{left: string[], right: string[] }, rowPinning{bottom: string[], top: string[] }, columnFilters: {id: string, value: unknown }[], globalFilter: any, sorting: {desc: boolean, id: string }[], expanded:?, grouping: string[], columnSizing:?, columnSizingInfo: { columnSizingStart: [string, number][], deltaOffset: null | number,deltaPercentage: null | number,isResizingColumn: false | string, startOffset: null | number, startSize: null | number } }-Change the default rendered element for the one passed as a child, merging their props and behavior.
onClickRow(row: Row<TData>) => void-Action function triggered when the user clicks on a row.
onResetTable() => void-Reset localStorage used for preferences (order table, number of rows...).
toolbarReactNode-Put anything in this toolbar : button, text, select...
selection{ createSelectionColumn?: boolean, totalSelectableCount?: number,selectionState?: {state, onSelectionChange}, handlers?: {isRowSelected?,toggleRow?,toggleSelectAll?,getSelectionCount?,clearSelection?,isAllSelected?,isSomeSelected?},selectionHeader?: {custom?: (props: {selectionState: SelectionState}) => ReactNode, actions?: (props: {selectionState: SelectionState}) => ReactNode} }-Activate and changes the default display or behavior of the table selection

Playground

Import from @filigran/ui :

Import {Separator} from '@filigran/ui'

Everything possible for declaring columns :

const columns = useMemo<ColumnDef<Person>[]>(
  () => [
    {
      id: 'select',
      size: 20,
      header: ({table}) => (
        <Checkbox
          className="flex"
          checked={
            table.getIsAllPageRowsSelected() ||
            (table.getIsSomePageRowsSelected() && 'indeterminate')
          }
          onCheckedChange={(value) =>
            table.toggleAllPageRowsSelected(!!value)
          }
          aria-label="Select all"
        />
      ),
      cell: ({row}) => (
        <Checkbox
          className="flex"
          checked={row.getIsSelected()}
          onClick={(e) => e.stopPropagation()}
          onCheckedChange={(value) => {
            row.toggleSelected(!!value)
          }}
          aria-label="Select row"
        />
      ),
      enableSorting: false,
      enableHiding: false,
      enableResizing: false
    },
    {
      id: 'firstName',
      accessorKey: 'firstName',
      enableHiding: true,
      enableSorting: false,
      cell: (info) => (
        <HighlightSearchTerm text={info.getValue() as string} />
      ),
      header: 'First name'
    },
    {
      accessorFn: (row) => row.lastName,
      id: 'lastName',
      enableHiding: false,
      cell: (info) => (
        <HighlightSearchTerm text={info.getValue() as string} />
      ),
      header: (header) => (
        <DataTableOptionsHeader
          column={header.column}
          title={'Last name'}
          menuItems={
            <>
              <DropdownMenuItem onClick={() => console.log(header.column)}>
                Log column
              </DropdownMenuItem>
              <DropdownMenuItem onClick={() => console.log(header.column)}>
                Log column 2
              </DropdownMenuItem>
            </>
          }
        />
      )
    },
    {
      id: 'age',
      accessorKey: 'age',
      header: 'Age'
    }], [])

<DataTable
      data={data}
      columns={columns}
      isLoading={loading}
      i18nKey={isCheckedI18n ? frenchI18nKey : {}}
      tableOptions={{
        onRowSelectionChange: setRowSelection,
        getSortedRowModel: getSortedRowModel(),
        getPaginationRowModel: getPaginationRowModel(),
        onPaginationChange: setPagination,
        enableRowSelection: (row) => row.original.age > 18, //only enable row selection for adults
        onColumnOrderChange: setColumnOrder
      }}
      tableState={{
        rowSelection,
        pagination,
        columnOrder,
        columnPinning: {
          left: ['select']
        } //Force left column on the left, can not be pinned.
      }}
      selection={{
        createDefaultSelectionColumn: true,
        totalSelectableCount: totalSelectable,
        defaultSelectionHeaderActions: ({ selectionState }) => (
          <>
            <Button
              variant="ghost-destructive"
              size="icon"
              className="border"
              onClick={() => console.log(selectionState)}>
              <Trash className="size-4" />
            </Button>
          </>
        ),
      }}
      onClickRow={(row) => console.log(row)} // Action on click
    />