Filigran

Datatable Example

Translate in French
1 - 50 / 500
First name
lastName
Age
Visits
Status
Description
Profile Progress
MerrittLesch393single72
HershelKlein30446relationship94
BrigitteStanton19599relationship94
DudleyO'Connell4845complicated64
GregoriaGutkowski18861relationship4
AlbinaBahringer6533relationship66
AndreaneShields-Tillman31720relationship87
StewartBarton10605complicated81
DominickSchamberger3877complicated11
JaredHeaney11200complicated52
ElbertHintz22358relationship30
YvetteGutkowski34765relationship36
SanfordHerman30591complicated70
MollieFranecki3942single70
TyreeMiller22937single6
SylvesterZieme15560relationship21
DuaneHyatt31236single73
GoldaMetz18375complicated17
JenniferJacobs7457complicated41
CharlieMcKenzie26424single90
GiovaniAnkunding13672single84
HubertGraham39965single51
KelvinRoberts12782relationship66
DeannaWilkinson34645complicated55
ValentineBosco1367relationship72
ShaunBuckridge2688single37
ArchBotsford39525complicated10
KobyHayes2517relationship43
ElijahBreitenberg40460complicated75
BrendanKshlerin14826single88
MichealGusikowski10776relationship68
AleenLemke4760complicated70
StellaReinger27937complicated61
HermanKrajcik3548complicated75
NorwoodTurner27529relationship21
SherriGleason22879complicated41
AdrienneMorar14303single49
FredCruickshank1755complicated90
ShaneTromp32399relationship87
PatrickBayer483relationship21
HannahKub0112single2
LeopoldoMoen39311complicated23
OsvaldoKoepp11650relationship2
BradfordTowne9472single69
GloriaReinger29902relationship77
BereniceConroy25119relationship24
AlbertaParisian3432complicated72
RosemarieJaskolski37211single95
CandaceAufderhar13361single10
JaquanSawayn8369complicated50
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
    />