0.1.6 • Published 2 years ago

@fabiendeborde/mantine-datagrid v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Mantine Datagrid

GitHub release Size GitHub license

A wrapper around React Table (TanStack Table v8) using Mantine.

This library requires the following packages: @emotion/react, @mantine/core, @mantine/hooks, @mantine/dates and it exposes this package: @tanstack/react-table.\ It was heavily inspired by the work of Yannick Küchlin (GitHub repository) and Milan Jain(CodeSandbox) from this discussion.

I do not plan to really maintain or update this library except if it is needed by other private projects, but feel free to leave suggestions or bug reports, I'll try my best to check them as soon as I can.

Setup

npm i @fabiendeborde/mantine-datagrid
yarn add @fabiendeborde/mantine-datagrid

Props

nametypedefaultdescription
data -required-T[]-Table data
columns -required-ColumnDef<T, unknown>[]-Table columns definitions
loadingbooleanfalseShow a loader on loading (LoadingOverlay)
debugbooleanfalseEnable React Table debug logging
containerPropsScrollAreaPropsundefinedTable container props (https://mantine.dev/core/scroll-area/)
containerStyleCSSPropertiesundefinedTable container style
containerRefMutableRefObjectundefinedTable container ref
containerMaxHeightnumberundefinedTable container max height in pixel
onRowClick(row: T) => voidundefinedCallback on Table row click (with row values)
withRowSelectionbooleanfalseEnable Row selection
onRowSelection(selection: RowSelectionState) => voidundefinedCallback on row selection (with selection state)
withPaginationbooleanundefinedEnable pagination
withTopPaginationbooleanfalseEnable pagination above the Table
manualPaginationbooleanundefinedEnables manual pagination
paginationOptionsobjectundefinedPagination options
・paginationOptions.initialPageIndexnumber0Initial page index
・paginationOptions.initialPageSizenumber10Initial page size (rows per page)
・paginationOptions.pageIndexnumber0Controlled page index (only used when manual pagination is `true)
・paginationOptions.pageSizenumber10Controlled page size (rows per page) (only used when manual pagination is `true)
・paginationOptions.pageSizesstring[]"10", "25", "50", "100"Sets of string for page size (rows per page) selections.
・paginationOptions.positionGroupPositionundefinedPagination position
・paginationOptions.rowsCountnumberundefinedSet data total rows (only used when manual pagination is true)
・paginationOptions.pageCountnumberundefinedSet data total pages (only used when manual pagination is true)
paginationRefMutableRefObjectundefinedTable pagination ref
onPaginationChange(filter: PaginationState) => voidundefinedCallback on pagination change (with pagination state)
withGlobalFilterbooleanfalseEnable global filter (not recommanded in manual mode, as the global filter will only work on the current page)
onColumnFilterChange(filter: ColumnFiltersState) => voidundefinedCcallback on column filter change (with column fiter state)
onSortingChange(sort: SortingState) => voidundefinedCallback on column sort change (with column sorting state)
stripedbooleanfalseIf true every odd row of table will have gray background color
highlightOnHoverbooleanfalseIf true row will have hover color
horizontalSpacingMantineNumberSize'xs'Horizontal cells spacing from theme.spacing or number to set value in px
verticalSpacingMantineNumberSize'xs'Vertical cells spacing from theme.spacing or number to set value in px
fontSizeMantineNumberSize'sm'Sets font size of all text inside table
withVirtualizedRowsbooleanfalseEnable Virtualized Rows
virtualizedRowOverscannumberundefinedThe amount of items to load both behind and ahead of the current window range
gridStateGridState { pagination?: PaginationState; sorting?: SortingState; columnFilters?: ColumnFiltersState;}undefinedGrid State used for controlled pagination & filters

Usage

<Datagrid<User>
  loading={false}
  debug={false}
  columns={columns}
  data={data}
  withPagination
  withTopPagination={false}
  paginationOptions={{
    initialPageIndex: 0,
    initialPageSize: 10,
    pageSizes: ['10', '25', '50', '100', '250', '1000'],
    position: 'right'
  }}
  withGlobalFilter
  withVirtualizedRows
  virtualizedRowOverscan={25}
/>

License

Distributed under the ISC license. See LICENSE for more information.

TODO

[] update readme [] add tests [] add autocomplete in string filter (use mantine component, withAutocomplete props?) [] improve example project (use real API?)

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago