Filigran

Datatable Example

Translate in French
1 - 50 / 500
First name
lastName
Age
Visits
Status
Description
Profile Progress
BarbaraGorczany33835complicated6
HazelNader35669complicated67
MaidaBednar39957single93
GenevaSchmeler14252complicated41
CliftonPacocha29757complicated96
EnriqueYundt5996complicated77
FrederickHickle33770relationship58
MamieLangworth9276complicated73
DejahMayert29956relationship12
SimonSchuppe25301complicated58
LowellKris38914single62
DelbertEbert10965complicated47
JanisBosco2630single96
BenYost16702single0
CandiceHahn20510complicated59
GeraldLesch257relationship22
MindyWilderman33919complicated27
ChristyRunolfsdottir5364single91
KeyshawnCartwright2057single10
FernandoOberbrunner22636relationship95
GeraldHarvey37845single71
AmyQuitzon36934single9
MelanieYost15691single4
GiovannyHarris26180relationship77
FelipeBradtke36318complicated37
RubySteuber26334complicated33
AlysonPaucek28485relationship78
MarjorieCummerata0333complicated61
RuthGreen-Runte33362single91
SusannaReilly12163complicated40
BenjaminMurray31743relationship28
CoralieStokes39703complicated72
TammyMedhurst-Gulgowski15562single37
TyreeBeatty36764single7
AudreyWintheiser39337single88
GretchenRowe10693relationship35
KoleOndricka2929single29
AdeliaNicolas29202relationship85
MckenzieMcClure34309single24
ArvidChristiansen1643relationship71
MckenzieMoen3668relationship18
IrmaHermann1626complicated70
IlianaHoeger25141single82
WilmaLuettgen33489single78
TyreseDoyle37921complicated64
RigobertoHalvorson-Harris36755complicated33
MarcusShanahan3264complicated60
EdmondEbert32956complicated42
IraJacobi7102single8
FeltonBogisich35247relationship56
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
    />