Filigran

Datatable Example

Translate in French
1 - 50 / 500
First name
lastName
Age
Visits
Status
Description
Profile Progress
AnastacioWintheiser40898complicated48
DameonLittle2575relationship79
JenningsHowe0549relationship13
CandelarioMarks36642relationship95
ElviraPrice-Hirthe19936complicated95
BruceBartoletti17599complicated33
HarleyNitzsche36214single57
SandrineBlick20981relationship42
LucindaBruen27918complicated88
MarioKoepp19382single81
BrendanO'Kon14947relationship90
JackelineD'Amore18941single80
HelgaLang26372single76
CarolineDare4217complicated96
BeverlyFunk39493single32
MyahVeum-Witting26418complicated33
WillisThompson22199single55
PhilDoyle199complicated88
TitoNolan1557complicated3
VickiDickens4411relationship90
MamieStiedemann26812single100
LaurenBayer34740complicated34
FerminBeatty35383single70
CandiceHilll20904relationship32
RobertoWehner19645relationship99
KaitlinDicki27374complicated67
GunnerYundt37988single76
AnahiHuels13317single84
AmeliaGutkowski3947single32
TheoDooley5553complicated17
AssuntaLeuschke1820relationship8
CloydPollich10746complicated64
GraysonKunde14206complicated60
EileenAnkunding15309relationship97
DeweyNicolas27565relationship20
FelixBlock6547relationship97
TashaPfeffer3593complicated2
VidaCartwright29single83
FredaBechtelar2481complicated70
AngieHaag12256single65
CedricO'Reilly30341single9
NoelKoss7958relationship45
NathanialUpton19258complicated33
TheresaLangosh17788relationship73
BritneyTrantow279relationship35
WhitneyAufderhar25761relationship50
MaidaBashirian35818relationship9
WilsonSteuber39353complicated6
LuluLarson8272relationship18
GilbertPredovic1481relationship89
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
    />