Filigran

Datatable Example

Translate in French
1 - 50 / 500
First name
lastName
Age
Visits
Status
Description
Profile Progress
CamillaKunde1067complicated48
KentFay19630single25
ImeldaVon23294complicated69
StanleySchaefer21833relationship46
ChrisNikolaus4532relationship90
ConsueloMante36806complicated36
KenBoyle33258complicated40
JimmyKoch10839relationship31
EugeneWilderman35815single91
MertieDibbert-Kilback36970relationship44
KirstenBlock31504relationship18
FeliciaHettinger2842complicated40
PatsyChristiansen6399single10
StephenWehner15161complicated85
KayCrooks12436single28
PhoebeMarks25350complicated29
AmosHerzog13159relationship76
AntoneThiel4587relationship19
BerthaDietrich1193single20
HenriettaWeimann3204complicated76
EdLeuschke10581relationship27
CarolynHartmann2512single83
LulaKeebler15387single90
ErichPfannerstill0406single97
NeilGoodwin39177relationship44
NeomaHermann40634single99
CarlottaBechtelar2672relationship40
MaryjaneFay21670single86
TanyaBalistreri4348relationship69
JosefaReynolds5612single99
RachelleKeeling26851complicated2
PercyCormier39142complicated40
BeulahWindler36980relationship23
DasiaStamm21482complicated68
LoyalGerlach11356complicated33
WilburMorissette2258relationship65
CaleCruickshank33229complicated94
CoyLittel12995single84
LorenzoJakubowski36887single24
SergioPfannerstill25767relationship27
AnnaRohan40267relationship75
GabrielHyatt19250relationship31
CarliHahn0847single44
KareemDaugherty23873complicated35
GlennKris18886complicated39
TheodoraHyatt278complicated3
DestinyKunde079complicated89
VanWolff19459complicated19
PenelopeSchultz33544relationship24
TashaEmmerich22544single36
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
    />