mantine-datatable 9.7.5 → 9.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 – 2026 Ionuț-Cristian Florescu
3
+ Copyright (c) 2022-present Ionuț-Cristian Florescu
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -49,7 +49,7 @@ Used by [Microsoft](https://www.microsoft.com/) in [Agent Lightning](https://git
49
49
 
50
50
  > _Thank you for the wonderful, useful, and beautiful DataTable that has allowed me to create several applications without any problem 👏_
51
51
 
52
- Mantine DataTable is used by developers and companies around the world, from startups to S&P 500, such as: [Microsoft](https://www.microsoft.com/), [Namecheap](https://www.namecheap.com/), [EasyWP](https://www.easywp.com/), [CodeParrot.AI](https://codeparrot.ai), [OmicsStudio](https://omicsstudio.com), [SegmentX](https://segmentx.ai), [Aquarino](https://www.aquarino.com.br/), [Dera](https://getdera.com/), [kapa.ai](https://kapa.ai/), [exdatis.ai](https://exdatis.ai/), [teachfloor](https://www.teachfloor.com/), [MARKUP](https://www.getmarkup.com/), [BookieBase](https://bookiebase.ie/), [zipline](https://zipline.diced.tech/), [Pachtop](https://github.com/pacholoamit/pachtop), [Ganymede](https://github.com/Zibbp/ganymede), [COH3 Stats](https://coh3stats.com/), [Culver City Rental Registry](https://www.ccrentals.org/) and many more.
52
+ Mantine DataTable is used by developers and companies around the world, from startups to S&P 500, such as: [Microsoft](https://www.microsoft.com/), [Namecheap](https://www.namecheap.com/), [EasyWP](https://www.easywp.com/), [swapp.ro](https://swapp.ro/), [OmicsStudio](https://omicsstudio.com), [SalesPlayX](https://www.salesplayx.com/), [Aquarino](https://www.aquarino.com.br/), [kapa.ai](https://kapa.ai/), [exdatis.ai](https://exdatis.ai/), [teachfloor](https://www.teachfloor.com/), [MARKUP](https://www.getmarkup.com/), [BookieBase](https://bookiebase.ie/), [zipline](https://zipline.diced.tech/), [Pachtop](https://github.com/pacholoamit/pachtop), [Ganymede](https://github.com/Zibbp/ganymede), [COH3 Stats](https://coh3stats.com/), [Culver City Rental Registry](https://www.ccrentals.org/), and many more.
53
53
 
54
54
  If you're using Mantine DataTable in your project, please drop me a line at the email address listed in my [GitHub profile](https://github.com/icflorescu) and I'll be happy to add it to the list and on the [documentation website](https://icflorescu.github.io/mantine-datatable/).
55
55
 
package/dist/index.d.ts CHANGED
@@ -30,6 +30,10 @@ export type DataTableColumn<T = Record<string, unknown>> = {
30
30
  * If true, column will be sortable.
31
31
  */
32
32
  sortable?: boolean;
33
+ /**
34
+ * Optional key passed to `onSortStatusChange` as `sortKey`, useful when the value
35
+ * to sort by differs from the column accessor (e.g. a database field name).
36
+ */
33
37
  sortKey?: string;
34
38
  /**
35
39
  * If set to true, the column can be dragged.
@@ -195,6 +199,92 @@ export type DataTableCellClickHandler<T = Record<string, unknown>> = (params: {
195
199
  */
196
200
  columnIndex: number;
197
201
  }) => void;
202
+ export type DataTableColorProps<T> = {
203
+ /**
204
+ * Data table text color.
205
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
206
+ * or an object with `light` and `dark` keys and `MantineColor` values.
207
+ */
208
+ c?: MantineColor | {
209
+ light: MantineColor;
210
+ dark: MantineColor;
211
+ };
212
+ /**
213
+ * Data table background color.
214
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
215
+ * or an object with `light` and `dark` keys and `MantineColor` values.
216
+ */
217
+ backgroundColor?: MantineColor | {
218
+ light: MantineColor;
219
+ dark: MantineColor;
220
+ };
221
+ /**
222
+ * Color of table borders, applied to all borders except row borders.
223
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
224
+ * or an object with `light` and `dark` keys and `MantineColor` values.
225
+ */
226
+ borderColor?: MantineColor | {
227
+ light: MantineColor;
228
+ dark: MantineColor;
229
+ };
230
+ /**
231
+ * Color of row borders.
232
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
233
+ * or an object with `light` and `dark` keys and `MantineColor` values.
234
+ */
235
+ rowBorderColor?: MantineColor | {
236
+ light: MantineColor;
237
+ dark: MantineColor;
238
+ };
239
+ /**
240
+ * Background color of striped rows.
241
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
242
+ * or an object with `light` and `dark` keys and `MantineColor` values.
243
+ */
244
+ stripedColor?: MantineColor | {
245
+ light: MantineColor;
246
+ dark: MantineColor;
247
+ };
248
+ /**
249
+ * Background color of hover-highlighted row.
250
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
251
+ * or an object with `light` and `dark` keys and `MantineColor` values.
252
+ */
253
+ highlightOnHoverColor?: MantineColor | {
254
+ light: MantineColor;
255
+ dark: MantineColor;
256
+ };
257
+ /**
258
+ * Background color of selected rows.
259
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
260
+ * or an object with `light` and `dark` keys and `MantineColor` values.
261
+ * Defaults to the light variant of the theme's primary color.
262
+ */
263
+ selectionColor?: MantineColor | {
264
+ light: MantineColor;
265
+ dark: MantineColor;
266
+ };
267
+ /**
268
+ * Data table row text color.
269
+ * A function that accepts row data and returns color.
270
+ * The returned color can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
271
+ * or an object with `light` and `dark` keys and `MantineColor` values.
272
+ */
273
+ rowColor?: (record: T, index: number) => MantineColor | undefined | {
274
+ light: MantineColor;
275
+ dark: MantineColor;
276
+ };
277
+ /**
278
+ * Data table row background color.
279
+ * A function that accepts row data and returns a background color.
280
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
281
+ * or an object with `light` and `dark` keys and `MantineColor` values.
282
+ */
283
+ rowBackgroundColor?: (record: T, index: number) => MantineColor | undefined | {
284
+ light: MantineColor;
285
+ dark: MantineColor;
286
+ };
287
+ };
198
288
  export type DataTableColumnGroup<T = Record<string, unknown>> = {
199
289
  /**
200
290
  * Used as the `key` prop for the created `<th />`.
@@ -230,6 +320,19 @@ export type DataTableColumnGroup<T = Record<string, unknown>> = {
230
320
  */
231
321
  style?: MantineStyleProp;
232
322
  };
323
+ export type DataTableColumnProps<T = Record<string, unknown>> = {
324
+ /**
325
+ * Grouped columns.
326
+ */
327
+ groups: DataTableColumnGroup<T>[];
328
+ columns?: never;
329
+ } | {
330
+ groups?: never;
331
+ /**
332
+ * Visible columns.
333
+ */
334
+ columns: DataTableColumn<T>[];
335
+ };
233
336
  export type DataTableDefaultColumnProps<T = Record<string, unknown>> = Omit<DataTableColumn<T>, "accessor" | "hidden" | "visibleMediaQuery" | "render">;
234
337
  export type DataTableDraggableRowProps = {
235
338
  /**
@@ -258,6 +361,35 @@ export type DataTableEmptyStateProps = {
258
361
  */
259
362
  noRecordsIcon?: React.ReactNode;
260
363
  };
364
+ export type DataTableLoaderProps = {
365
+ /**
366
+ * Loader background blur (in pixels).
367
+ */
368
+ loaderBackgroundBlur?: number;
369
+ } & ({
370
+ loaderSize?: never;
371
+ loaderType?: never;
372
+ loaderColor?: never;
373
+ /**
374
+ * Custom loader component to use instead of default one.
375
+ */
376
+ customLoader?: React.ReactNode;
377
+ } | {
378
+ /**
379
+ * Loader size.
380
+ * @default `md` (Mantine Loader default)
381
+ */
382
+ loaderSize?: MantineSize | (string & NonNullable<unknown>) | number;
383
+ /**
384
+ * Loader type.
385
+ */
386
+ loaderType?: MantineLoader;
387
+ /**
388
+ * Loader color.
389
+ */
390
+ loaderColor?: MantineColor;
391
+ customLoader?: never;
392
+ });
261
393
  export type DataTableOuterBorderProps = {
262
394
  withTableBorder?: never;
263
395
  borderRadius?: never;
@@ -271,7 +403,7 @@ export type DataTableOuterBorderProps = {
271
403
  */
272
404
  borderRadius?: MantineSize | (string & NonNullable<unknown>) | number;
273
405
  };
274
- type DataTablePageSizeSelectorProps = {
406
+ export type DataTablePageSizeSelectorProps = {
275
407
  onRecordsPerPageChange?: never;
276
408
  recordsPerPageOptions?: never;
277
409
  recordsPerPageLabel?: never;
@@ -415,124 +547,6 @@ export type DataTablePaginationProps = ({
415
547
  */
416
548
  renderPagination?: (ctx: DataTablePaginationRenderContext) => React.ReactNode;
417
549
  }) & DataTablePageSizeSelectorProps;
418
- type DataTableColorProps<T> = {
419
- /**
420
- * Data table text color.
421
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
422
- * or an object with `light` and `dark` keys and `MantineColor` values.
423
- */
424
- c?: MantineColor | {
425
- light: MantineColor;
426
- dark: MantineColor;
427
- };
428
- /**
429
- * Data table background color.
430
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
431
- * or an object with `light` and `dark` keys and `MantineColor` values.
432
- */
433
- backgroundColor?: MantineColor | {
434
- light: MantineColor;
435
- dark: MantineColor;
436
- };
437
- /**
438
- * Color of table borders, applied to all borders except row borders.
439
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
440
- * or an object with `light` and `dark` keys and `MantineColor` values.
441
- */
442
- borderColor?: MantineColor | {
443
- light: MantineColor;
444
- dark: MantineColor;
445
- };
446
- /**
447
- * Color of row borders.
448
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
449
- * or an object with `light` and `dark` keys and `MantineColor` values.
450
- */
451
- rowBorderColor?: MantineColor | {
452
- light: MantineColor;
453
- dark: MantineColor;
454
- };
455
- /**
456
- * Background color of striped rows.
457
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
458
- * or an object with `light` and `dark` keys and `MantineColor` values.
459
- */
460
- stripedColor?: MantineColor | {
461
- light: MantineColor;
462
- dark: MantineColor;
463
- };
464
- /**
465
- * Background color of hover-highlighted row.
466
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
467
- * or an object with `light` and `dark` keys and `MantineColor` values.
468
- */
469
- highlightOnHoverColor?: MantineColor | {
470
- light: MantineColor;
471
- dark: MantineColor;
472
- };
473
- /**
474
- * Data table row text color.
475
- * A function that accepts row data and returns color.
476
- * The returned color can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
477
- * or an object with `light` and `dark` keys and `MantineColor` values.
478
- */
479
- rowColor?: (record: T, index: number) => MantineColor | undefined | {
480
- light: MantineColor;
481
- dark: MantineColor;
482
- };
483
- /**
484
- * Data table row background color.
485
- * A function that accepts row data and returns background color color.
486
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
487
- * or an object with `light` and `dark` keys and `MantineColor` values.
488
- */
489
- rowBackgroundColor?: (record: T, index: number) => MantineColor | undefined | {
490
- light: MantineColor;
491
- dark: MantineColor;
492
- };
493
- };
494
- type DataTableColumnProps<T = Record<string, unknown>> = {
495
- /**
496
- * Grouped columns.
497
- */
498
- groups: DataTableColumnGroup<T>[];
499
- columns?: never;
500
- } | {
501
- groups?: never;
502
- /**
503
- * Visible columns.
504
- */
505
- columns: DataTableColumn<T>[];
506
- };
507
- type DataTableLoaderProps = {
508
- /**
509
- * Loader background blur (in pixels).
510
- */
511
- loaderBackgroundBlur?: number;
512
- } & ({
513
- loaderSize?: never;
514
- loaderType?: never;
515
- loaderColor?: never;
516
- /**
517
- * Custom loader component to use instead of default one.
518
- */
519
- customLoader?: React.ReactNode;
520
- } | {
521
- /**
522
- * Loader size.
523
- * @default `lg`.
524
- */
525
- loaderSize?: MantineSize | (string & NonNullable<unknown>) | number;
526
- /**
527
- * Loader type.
528
- */
529
- loaderType?: MantineLoader;
530
- /**
531
- * Loader color.
532
- */
533
- loaderColor?: MantineColor;
534
- customLoader?: never;
535
- });
536
550
  export type DataTableRowClickHandler<T = Record<string, unknown>> = (params: {
537
551
  /**
538
552
  * Click event.
@@ -607,7 +621,7 @@ export type DataTableRowExpansionProps<T = Record<string, unknown>> = {
607
621
  collapse: () => void;
608
622
  }) => React.ReactNode;
609
623
  };
610
- type DataTableScrollProps = {
624
+ export type DataTableScrollProps = {
611
625
  /**
612
626
  * Function to call when the DataTable is scrolled.
613
627
  */
@@ -655,7 +669,7 @@ export type DataTableSelectionProps<T = Record<string, unknown>> = {
655
669
  selectedRecords?: T[];
656
670
  /**
657
671
  * Callback fired when selected records change.
658
- * Receives and array of selected records as argument.
672
+ * Receives an array of selected records as argument.
659
673
  */
660
674
  onSelectedRecordsChange?: (selectedRecords: T[]) => void;
661
675
  /**
@@ -669,7 +683,7 @@ export type DataTableSelectionProps<T = Record<string, unknown>> = {
669
683
  /**
670
684
  * A function used to determine whether a certain record is selectable.
671
685
  * if the function returns false, the row selection checkbox is disabled.
672
- * Accepts the current recors and index as arguments and returns a boolean.
686
+ * Accepts the current record and index as arguments and returns a boolean.
673
687
  */
674
688
  isRecordSelectable?: (record: T, index: number) => boolean;
675
689
  /**
@@ -723,7 +737,7 @@ export type DataTableSortProps<T = Record<string, unknown>> = ({
723
737
  sortIcons?: {
724
738
  /**
725
739
  * Icon to display when column is sorted ascending.
726
- * Will be rotated 180deg for descending sort
740
+ * Will be flipped vertically for descending sort
727
741
  */
728
742
  sorted: React.ReactNode;
729
743
  /**
@@ -786,11 +800,11 @@ export type DataTableProps<T = Record<string, unknown>> = {
786
800
  */
787
801
  fetching?: boolean;
788
802
  /**
789
- * If true, the first column will be pinned to the left side of the table.
803
+ * If true, the first visible column will be pinned to the left side of the table (to the right side in RTL).
790
804
  */
791
805
  pinFirstColumn?: boolean;
792
806
  /**
793
- * If true, the last column will be pinned to the right side of the table.
807
+ * If true, the last visible column will be pinned to the right side of the table (to the left side in RTL).
794
808
  */
795
809
  pinLastColumn?: boolean;
796
810
  /**
@@ -798,8 +812,8 @@ export type DataTableProps<T = Record<string, unknown>> = {
798
812
  */
799
813
  defaultColumnProps?: DataTableDefaultColumnProps<T>;
800
814
  /**
801
- * If you want to use drag and drop as well as toggle to reorder and toggle columns
802
- * provide a unique key which will be used to store the column order in localStorage.
815
+ * Unique key used to persist the columns state (order, visibility, widths and pinning) in localStorage.
816
+ * Required if you want users' column dragging, toggling, resizing or pinning to survive page reloads.
803
817
  */
804
818
  storeColumnsKey?: string | undefined;
805
819
  /**
@@ -882,9 +896,9 @@ export type DataTableProps<T = Record<string, unknown>> = {
882
896
  */
883
897
  rowStyle?: (record: T, index: number) => MantineStyleProp | undefined;
884
898
  /**
885
- * Optional style passed to each row.
886
- * a function that receives the current record, its index, default row props and expanded element as arguments
887
- * and returns a React node representing the row.
899
+ * Optional function rendering a custom row.
900
+ * Receives the current record, its index, the default row props, the row cells (`children`)
901
+ * and the expanded element as arguments, and returns a React node representing the row.
888
902
  */
889
903
  rowFactory?: (props: {
890
904
  record: T;
@@ -897,7 +911,7 @@ export type DataTableProps<T = Record<string, unknown>> = {
897
911
  * Optional function returning a React node representing the table wrapper.
898
912
  * If not provided, no wrapper will be used.
899
913
  *
900
- * examplle: This function can be used with rowFactory if using drag and drop to pass context
914
+ * For example, it can be used together with `rowFactory` to provide a drag-and-drop context.
901
915
  */
902
916
  tableWrapper?: ({ children }: {
903
917
  children: React.ReactNode;
@@ -928,7 +942,7 @@ export type DataTableProps<T = Record<string, unknown>> = {
928
942
  } & Omit<TableProps, "onScroll" | "className" | "classNames" | "style" | "styles" | "p" | "px" | "py" | "pt" | "pb" | "layout" | "captionSide" | "c" | "color" | "borderColor" | "stripedColor" | "highlightOnHoverColor" | "stickyHeader" | "stickyHeaderOffset" | "onDragEnd"> & DataTableColorProps<T> & DataTableColumnProps<T> & DataTableOuterBorderProps & DataTableLoaderProps & DataTableEmptyStateProps & DataTablePaginationProps & DataTableSortProps<T> & DataTableScrollProps & DataTableSelectionProps<T>;
929
943
  export type WithOptionalProperty<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
930
944
  export type WithRequiredProperty<Type, Key extends keyof Type> = Type & { [Property in Key]-?: Type[Property]; };
931
- export declare function DataTable<T>({ withTableBorder, borderRadius, textSelectionDisabled, height, minHeight, maxHeight, shadow, verticalAlign, fetching, columns, storeColumnsKey, groups, pinFirstColumn, pinLastColumn, defaultColumnProps, defaultColumnRender, idAccessor, records, selectionTrigger, selectedRecords, onSelectedRecordsChange, selectionColumnClassName, selectionColumnStyle, isRecordSelectable, selectionCheckboxProps, allRecordsSelectionCheckboxProps, getRecordSelectionCheckboxProps, sortStatus, sortIcons, onSortStatusChange, horizontalSpacing, page, onPageChange, totalRecords, recordsPerPage, onRecordsPerPageChange, recordsPerPageOptions, recordsPerPageLabel, paginationWithEdges, paginationWithControls, paginationActiveTextColor, paginationActiveBackgroundColor, paginationSize, paginationText, paginationWrapBreakpoint, getPaginationControlProps, getPaginationItemProps, renderPagination, loaderBackgroundBlur, customLoader, loaderSize, loaderType, loaderColor, loadingText, emptyState, noRecordsText, noRecordsIcon, highlightOnHover, striped, noHeader, onRowClick, onRowDoubleClick, onRowContextMenu, onCellClick, onCellDoubleClick, onCellContextMenu, onScroll, onScrollToTop, onScrollToBottom, onScrollToLeft, onScrollToRight, c, backgroundColor, borderColor, rowBorderColor, stripedColor, highlightOnHoverColor, rowColor, rowBackgroundColor, rowExpansion, rowClassName, rowStyle, customRowAttributes, scrollViewportRef, scrollAreaProps, tableRef, bodyRef, m, my, mx, mt, mb, ml, mr, className, classNames, style, styles, rowFactory, tableWrapper, ...otherProps }: DataTableProps<T>): JSX.Element;
945
+ export declare function DataTable<T>({ withTableBorder, borderRadius, textSelectionDisabled, height, minHeight, maxHeight, shadow, verticalAlign, fetching, columns, storeColumnsKey, groups, pinFirstColumn, pinLastColumn, defaultColumnProps, defaultColumnRender, idAccessor, records, selectionTrigger, selectedRecords, onSelectedRecordsChange, selectionColumnClassName, selectionColumnStyle, isRecordSelectable, selectionCheckboxProps, allRecordsSelectionCheckboxProps, getRecordSelectionCheckboxProps, sortStatus, sortIcons, onSortStatusChange, horizontalSpacing, page, onPageChange, totalRecords, recordsPerPage, onRecordsPerPageChange, recordsPerPageOptions, recordsPerPageLabel, paginationWithEdges, paginationWithControls, paginationActiveTextColor, paginationActiveBackgroundColor, paginationSize, paginationText, paginationWrapBreakpoint, getPaginationControlProps, getPaginationItemProps, renderPagination, loaderBackgroundBlur, customLoader, loaderSize, loaderType, loaderColor, loadingText, emptyState, noRecordsText, noRecordsIcon, highlightOnHover, striped, noHeader, onRowClick, onRowDoubleClick, onRowContextMenu, onCellClick, onCellDoubleClick, onCellContextMenu, onScroll, onScrollToTop, onScrollToBottom, onScrollToLeft, onScrollToRight, c, backgroundColor, borderColor, rowBorderColor, stripedColor, highlightOnHoverColor, selectionColor, rowColor, rowBackgroundColor, rowExpansion, rowClassName, rowStyle, customRowAttributes, scrollViewportRef, scrollAreaProps, tableRef, bodyRef, m, my, mx, mt, mb, ml, mr, className, classNames, style, styles, rowFactory, tableWrapper, ...otherProps }: DataTableProps<T>): JSX.Element;
932
946
  export declare function DataTableDraggableRow({ className, children, isDragging, ref: refProp, ...otherProps }: DataTableDraggableRowProps & {
933
947
  ref?: Ref<HTMLTableRowElement>;
934
948
  }): JSX.Element;