material-react-table 0.7.6 → 0.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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/dist/MaterialReactTable.d.ts +18 -16
  3. package/dist/body/MRT_TableBody.d.ts +0 -1
  4. package/dist/body/MRT_TableBodyCell.d.ts +1 -0
  5. package/dist/body/MRT_TableBodyRow.d.ts +0 -1
  6. package/dist/buttons/MRT_CopyButton.d.ts +2 -1
  7. package/dist/enums.d.ts +2 -2
  8. package/dist/filtersFNs.d.ts +31 -30
  9. package/dist/footer/MRT_TableFooter.d.ts +0 -1
  10. package/dist/head/MRT_TableHead.d.ts +0 -1
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
  12. package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
  13. package/dist/localization.d.ts +6 -2
  14. package/dist/material-react-table.cjs.development.js +550 -575
  15. package/dist/material-react-table.cjs.development.js.map +1 -1
  16. package/dist/material-react-table.cjs.production.min.js +1 -1
  17. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  18. package/dist/material-react-table.esm.js +553 -578
  19. package/dist/material-react-table.esm.js.map +1 -1
  20. package/dist/table/MRT_Table.d.ts +0 -1
  21. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -0
  22. package/dist/toolbar/MRT_ToolbarTop.d.ts +3 -0
  23. package/dist/utils.d.ts +1 -1
  24. package/package.json +24 -27
  25. package/src/MaterialReactTable.tsx +24 -24
  26. package/src/body/MRT_TableBody.tsx +3 -11
  27. package/src/body/MRT_TableBodyCell.tsx +105 -51
  28. package/src/body/MRT_TableBodyRow.tsx +21 -30
  29. package/src/buttons/MRT_ColumnPinningButtons.tsx +28 -40
  30. package/src/buttons/MRT_CopyButton.tsx +5 -3
  31. package/src/buttons/MRT_EditActionButtons.tsx +1 -2
  32. package/src/buttons/MRT_ExpandAllButton.tsx +25 -18
  33. package/src/buttons/MRT_ExpandButton.tsx +27 -21
  34. package/src/enums.ts +2 -2
  35. package/src/filtersFNs.ts +71 -81
  36. package/src/footer/MRT_TableFooter.tsx +6 -16
  37. package/src/footer/MRT_TableFooterCell.tsx +16 -15
  38. package/src/footer/MRT_TableFooterRow.tsx +6 -8
  39. package/src/head/MRT_TableHead.tsx +5 -16
  40. package/src/head/MRT_TableHeadCell.tsx +120 -50
  41. package/src/head/MRT_TableHeadRow.tsx +8 -15
  42. package/src/inputs/MRT_EditCellTextField.tsx +3 -3
  43. package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
  44. package/src/inputs/MRT_FilterTextField.tsx +76 -41
  45. package/src/inputs/MRT_SelectCheckbox.tsx +15 -17
  46. package/src/localization.ts +13 -5
  47. package/src/menus/MRT_ColumnActionMenu.tsx +13 -12
  48. package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
  49. package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
  50. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +4 -6
  51. package/src/table/MRT_Table.tsx +5 -16
  52. package/src/table/MRT_TableContainer.tsx +7 -78
  53. package/src/table/MRT_TableRoot.tsx +43 -51
  54. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
  55. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +13 -28
  56. package/src/toolbar/MRT_ToolbarBottom.tsx +23 -5
  57. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +30 -29
  58. package/src/toolbar/MRT_ToolbarTop.tsx +24 -25
@@ -1,7 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
- pinned: 'left' | 'center' | 'right' | 'none';
5
4
  tableInstance: MRT_TableInstance;
6
5
  }
7
6
  export declare const MRT_Table: FC<Props>;
@@ -1,6 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
+ stackAlertBanner?: boolean;
4
5
  tableInstance: MRT_TableInstance;
5
6
  }
6
7
  export declare const MRT_ToolbarAlertBanner: FC<Props>;
@@ -7,7 +7,10 @@ export declare const commonToolbarStyles: ({ theme }: {
7
7
  backgroundColor: string;
8
8
  backgroundImage: string;
9
9
  display: string;
10
+ minHeight: string;
11
+ overflow: string;
10
12
  p: string;
13
+ transition: string;
11
14
  width: string;
12
15
  zIndex: number;
13
16
  };
package/dist/utils.d.ts CHANGED
@@ -7,6 +7,6 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
7
7
  export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
8
  [key: string]: MRT_FilterFn<{}>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
- "version": "0.7.6",
2
+ "version": "0.8.0",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
- "description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
5
+ "description": "A fully featured Material UI implementation of Tanstack react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
6
6
  "author": "Kevin Vandy",
7
7
  "keywords": [
8
8
  "react-table",
9
9
  "material-ui",
10
- "material-table"
10
+ "material-table",
11
+ "tanstack table"
11
12
  ],
12
13
  "repository": {
13
14
  "type": "git",
@@ -55,39 +56,35 @@
55
56
  }
56
57
  ],
57
58
  "devDependencies": {
58
- "@babel/core": "^7.17.9",
59
+ "@babel/core": "^7.18.2",
59
60
  "@emotion/react": "^11.9.0",
60
61
  "@emotion/styled": "^11.8.1",
61
- "@etchteam/storybook-addon-status": "^4.2.1",
62
- "@faker-js/faker": "^6.2.0",
63
- "@mui/icons-material": "^5.6.2",
64
- "@mui/material": "^5.6.3",
62
+ "@faker-js/faker": "^6.3.1",
63
+ "@mui/icons-material": "^5.8.0",
64
+ "@mui/material": "^5.8.1",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
- "@storybook/addon-a11y": "^6.4.22",
67
- "@storybook/addon-actions": "^6.4.22",
68
- "@storybook/addon-console": "^1.2.3",
69
- "@storybook/addon-essentials": "^6.4.22",
66
+ "@storybook/addon-a11y": "^6.5.5",
67
+ "@storybook/addon-actions": "^6.5.5",
68
+ "@storybook/addon-essentials": "^6.5.5",
70
69
  "@storybook/addon-info": "^5.3.21",
71
- "@storybook/addon-links": "^6.4.22",
72
- "@storybook/addon-storysource": "^6.4.22",
73
- "@storybook/addons": "^6.4.22",
74
- "@storybook/react": "^6.4.22",
75
- "@types/react": "^17.0.41",
76
- "@types/react-dom": "^17.0.14",
70
+ "@storybook/addon-links": "^6.5.5",
71
+ "@storybook/addons": "^6.5.5",
72
+ "@storybook/react": "^6.5.5",
73
+ "@types/react": "^18.0.9",
74
+ "@types/react-dom": "^18.0.5",
77
75
  "babel-loader": "^8.2.5",
78
- "eslint": "^8.14.0",
79
- "eslint-plugin-react-hooks": "^4.4.0",
80
- "husky": "^7.0.4",
76
+ "eslint": "^8.16.0",
77
+ "eslint-plugin-react-hooks": "^4.5.0",
78
+ "husky": "^8.0.1",
81
79
  "prettier": "^2.6.2",
82
80
  "react": "^17.0.2",
83
81
  "react-dom": "^17.0.2",
84
- "react-is": "^17.0.2",
82
+ "react-is": "^18.1.0",
85
83
  "size-limit": "^7.0.8",
86
- "storybook-addon-paddings": "^4.3.0",
87
- "storybook-dark-mode": "^1.0.9",
84
+ "storybook-dark-mode": "^1.1.0",
88
85
  "tsdx": "^0.14.1",
89
86
  "tslib": "^2.4.0",
90
- "typescript": "^4.6.3"
87
+ "typescript": "^4.7.2"
91
88
  },
92
89
  "peerDependencies": {
93
90
  "@emotion/react": ">=11",
@@ -97,7 +94,7 @@
97
94
  "react": ">=16.8"
98
95
  },
99
96
  "dependencies": {
100
- "@tanstack/react-table": "^8.0.0-alpha.48",
101
- "match-sorter": "^6.3.1"
97
+ "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
98
+ "@tanstack/react-table": "^8.0.0-alpha.89"
102
99
  }
103
100
  }
@@ -30,17 +30,18 @@ import {
30
30
  Cell,
31
31
  Column,
32
32
  ColumnDef,
33
- DefaultGenerics,
34
33
  FilterFn,
35
34
  FilterFnOption,
36
35
  Header,
37
36
  HeaderGroup,
38
- Options,
39
37
  Overwrite,
40
38
  PaginationState,
39
+ ReactTableGenerics,
41
40
  Row,
41
+ TableGenerics,
42
42
  TableInstance,
43
43
  TableState,
44
+ UseTableInstanceOptions,
44
45
  VisibilityState,
45
46
  } from '@tanstack/react-table';
46
47
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
@@ -50,7 +51,7 @@ import { MRT_TableRoot } from './table/MRT_TableRoot';
50
51
 
51
52
  export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
52
53
  Omit<
53
- Options<D>,
54
+ UseTableInstanceOptions<ReactTableGenerics>,
54
55
  'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
55
56
  >
56
57
  > & {
@@ -71,7 +72,7 @@ export interface MRT_RowModel<D extends Record<string, any> = {}> {
71
72
  export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
72
73
  TableInstance<
73
74
  Overwrite<
74
- Partial<DefaultGenerics>,
75
+ Partial<TableGenerics>,
75
76
  {
76
77
  Row: D;
77
78
  }
@@ -79,6 +80,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
79
80
  >,
80
81
  | 'getAllColumns'
81
82
  | 'getAllLeafColumns'
83
+ | 'getColumn'
82
84
  | 'getExpandedRowModel'
83
85
  | 'getPaginationRowModel'
84
86
  | 'getPrePaginationRowModel'
@@ -89,6 +91,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
89
91
  > & {
90
92
  getAllColumns: () => MRT_Column<D>[];
91
93
  getAllLeafColumns: () => MRT_Column<D>[];
94
+ getColumn: (columnId: string) => MRT_Column<D>;
92
95
  getExpandedRowModel: () => MRT_RowModel<D>;
93
96
  getPaginationRowModel: () => MRT_RowModel<D>;
94
97
  getPrePaginationRowModel: () => MRT_RowModel<D>;
@@ -100,11 +103,11 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
100
103
  idPrefix: string;
101
104
  localization: MRT_Localization;
102
105
  };
103
- setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
104
- setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
106
+ setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
107
+ setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
105
108
  setCurrentFilterFns: Dispatch<
106
109
  SetStateAction<{
107
- [key: string]: MRT_FilterFn<D>;
110
+ [key: string]: MRT_FilterFn;
108
111
  }>
109
112
  >;
110
113
  setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
@@ -123,10 +126,13 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
123
126
  currentFilterFns: Record<string, string | Function>;
124
127
  currentGlobalFilterFn: Record<string, string | Function>;
125
128
  isDensePadding: boolean;
129
+ isLoading: boolean;
126
130
  isFullScreen: boolean;
131
+ pagination: Partial<PaginationState>;
127
132
  showFilters: boolean;
128
133
  showGlobalFilter: boolean;
129
- pagination: Partial<PaginationState>;
134
+ showProgressBars: boolean;
135
+ showSkeletons: boolean;
130
136
  };
131
137
 
132
138
  export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
@@ -276,6 +282,9 @@ export type MRT_Column<D extends Record<string, any> = {}> = Omit<
276
282
  > &
277
283
  MRT_ColumnDef<D> & {
278
284
  columns?: MRT_Column<D>[];
285
+ columnDef: MRT_ColumnDef<D>;
286
+ header: string;
287
+ footer: string;
279
288
  };
280
289
 
281
290
  export type MRT_Header<D extends Record<string, any> = {}> = Omit<
@@ -294,18 +303,9 @@ export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
294
303
 
295
304
  export type MRT_Row<D extends Record<string, any> = {}> = Omit<
296
305
  Row<D>,
297
- | 'getVisibleCells'
298
- | 'getAllCells'
299
- | 'subRows'
300
- | 'original'
301
- | 'getLeftVisibleCells'
302
- | 'getRightVisibleCells'
303
- | 'getCenterVisibleCells'
306
+ 'getVisibleCells' | 'getAllCells' | 'subRows' | 'original'
304
307
  > & {
305
308
  getAllCells: () => MRT_Cell<D>[];
306
- getCenterVisibleCells: () => MRT_Cell<D>[];
307
- getLeftVisibleCells: () => MRT_Cell<D>[];
308
- getRightVisibleCells: () => MRT_Cell<D>[];
309
309
  getVisibleCells: () => MRT_Cell<D>[];
310
310
  subRows?: MRT_Row<D>[];
311
311
  original: D;
@@ -320,7 +320,7 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
320
320
  };
321
321
 
322
322
  export type MRT_FilterFn<D extends Record<string, any> = {}> =
323
- | FilterFn<D>
323
+ | FilterFn<TableGenerics>
324
324
  | FilterFnOption<D>
325
325
  | MRT_FILTER_OPTION
326
326
  | number
@@ -351,8 +351,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
351
351
  enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
352
352
  icons?: Partial<MRT_Icons>;
353
353
  idPrefix?: string;
354
- isLoading?: boolean;
355
- isReloading?: boolean;
356
354
  localization?: Partial<MRT_Localization>;
357
355
  muiLinearProgressProps?:
358
356
  | LinearProgressProps
@@ -760,8 +758,8 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
760
758
 
761
759
  export default <D extends Record<string, any> = {}>({
762
760
  autoResetExpanded = false,
763
- autoResetSorting = false,
764
761
  columnResizeMode = 'onEnd',
762
+ defaultColumn = { minSize: 50, maxSize: 1000, size: 150 },
765
763
  editingMode = 'row',
766
764
  enableColumnActions = true,
767
765
  enableColumnFilters = true,
@@ -774,6 +772,7 @@ export default <D extends Record<string, any> = {}>({
774
772
  enableHiding = true,
775
773
  enableMultiRowSelection = true,
776
774
  enablePagination = true,
775
+ enablePinning = false,
777
776
  enableSelectAll = true,
778
777
  enableSorting = true,
779
778
  enableStickyHeader = true,
@@ -793,12 +792,12 @@ export default <D extends Record<string, any> = {}>({
793
792
  }: MaterialReactTableProps<D>) => (
794
793
  <MRT_TableRoot
795
794
  autoResetExpanded={autoResetExpanded}
796
- autoResetSorting={autoResetSorting}
797
795
  columnResizeMode={columnResizeMode}
796
+ defaultColumn={defaultColumn}
798
797
  editingMode={editingMode}
799
798
  enableColumnActions={enableColumnActions}
800
- enableColumnResizing={enableColumnResizing}
801
799
  enableColumnFilters={enableColumnFilters}
800
+ enableColumnResizing={enableColumnResizing}
802
801
  enableDensePaddingToggle={enableDensePaddingToggle}
803
802
  enableExpandAll={enableExpandAll}
804
803
  enableFilters={enableFilters}
@@ -807,6 +806,7 @@ export default <D extends Record<string, any> = {}>({
807
806
  enableHiding={enableHiding}
808
807
  enableMultiRowSelection={enableMultiRowSelection}
809
808
  enablePagination={enablePagination}
809
+ enablePinning={enablePinning}
810
810
  enableSelectAll={enableSelectAll}
811
811
  enableSorting={enableSorting}
812
812
  enableStickyHeader={enableStickyHeader}
@@ -4,15 +4,13 @@ import { MRT_TableBodyRow } from './MRT_TableBodyRow';
4
4
  import { MRT_TableInstance } from '..';
5
5
 
6
6
  interface Props {
7
- pinned: 'left' | 'center' | 'right' | 'none';
8
7
  tableInstance: MRT_TableInstance;
9
8
  }
10
9
 
11
- export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
10
+ export const MRT_TableBody: FC<Props> = ({ tableInstance }) => {
12
11
  const {
13
12
  getPaginationRowModel,
14
13
  getPrePaginationRowModel,
15
- getTableBodyProps,
16
14
  options: { enablePagination, muiTableBodyProps },
17
15
  } = tableInstance;
18
16
 
@@ -20,22 +18,16 @@ export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
20
18
  ? getPaginationRowModel().rows
21
19
  : getPrePaginationRowModel().rows;
22
20
 
23
- const mTableBodyProps =
21
+ const tableBodyProps =
24
22
  muiTableBodyProps instanceof Function
25
23
  ? muiTableBodyProps({ tableInstance })
26
24
  : muiTableBodyProps;
27
25
 
28
- const tableBodyProps = {
29
- ...getTableBodyProps(),
30
- ...mTableBodyProps,
31
- };
32
-
33
26
  return (
34
27
  <TableBody {...tableBodyProps}>
35
28
  {rows.map((row) => (
36
29
  <MRT_TableBodyRow
37
- key={row.getRowProps().key}
38
- pinned={pinned}
30
+ key={row.id}
39
31
  row={row}
40
32
  tableInstance={tableInstance}
41
33
  />
@@ -1,25 +1,27 @@
1
1
  import React, { FC, MouseEvent, useMemo } from 'react';
2
- import { Skeleton, TableCell } from '@mui/material';
2
+ import { alpha, darken, lighten, Skeleton, TableCell } from '@mui/material';
3
3
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
4
4
  import type { MRT_Cell, MRT_TableInstance } from '..';
5
5
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
6
6
 
7
7
  interface Props {
8
8
  cell: MRT_Cell;
9
+ enableHover?: boolean;
9
10
  tableInstance: MRT_TableInstance;
10
11
  }
11
12
 
12
- export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
13
+ export const MRT_TableBodyCell: FC<Props> = ({
14
+ cell,
15
+ enableHover,
16
+ tableInstance,
17
+ }) => {
13
18
  const {
14
- getIsSomeColumnsPinned,
15
19
  getState,
16
20
  options: {
17
21
  editingMode,
18
22
  enableClickToCopy,
19
23
  enableEditing,
20
- enablePinning,
21
24
  idPrefix,
22
- isLoading,
23
25
  muiTableBodyCellProps,
24
26
  muiTableBodyCellSkeletonProps,
25
27
  onCellClick,
@@ -27,7 +29,13 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
27
29
  setCurrentEditingCell,
28
30
  } = tableInstance;
29
31
 
30
- const { currentEditingCell, currentEditingRow, isDensePadding } = getState();
32
+ const {
33
+ currentEditingCell,
34
+ currentEditingRow,
35
+ isDensePadding,
36
+ isLoading,
37
+ showSkeletons,
38
+ } = getState();
31
39
 
32
40
  const { column, row } = cell;
33
41
 
@@ -42,7 +50,6 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
42
50
  : column.muiTableBodyCellProps;
43
51
 
44
52
  const tableCellProps = {
45
- ...cell.getCellProps(),
46
53
  ...mTableCellBodyProps,
47
54
  ...mcTableCellBodyProps,
48
55
  };
@@ -50,10 +57,10 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
50
57
  const skeletonWidth = useMemo(
51
58
  () =>
52
59
  column.columnDefType === 'display'
53
- ? column.getWidth() / 2
54
- : Math.random() * (column.getWidth() - column.getWidth() / 3) +
55
- column.getWidth() / 3,
56
- [column.columnDefType, column.getWidth()],
60
+ ? column.getSize() / 2
61
+ : Math.random() * (column.getSize() - column.getSize() / 3) +
62
+ column.getSize() / 3,
63
+ [column.columnDefType, column.getSize()],
57
64
  );
58
65
 
59
66
  const isEditable =
@@ -84,6 +91,26 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
84
91
  }
85
92
  };
86
93
 
94
+ const getIsLastLeftPinnedColumn = () => {
95
+ return (
96
+ column.getIsPinned() === 'left' &&
97
+ tableInstance.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
98
+ );
99
+ };
100
+
101
+ const getIsFirstRightPinnedColumn = () => {
102
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
103
+ };
104
+
105
+ const getTotalRight = () => {
106
+ return (
107
+ (tableInstance.getRightLeafHeaders().length -
108
+ 1 -
109
+ column.getPinnedIndex()) *
110
+ 150
111
+ );
112
+ };
113
+
87
114
  return (
88
115
  <TableCell
89
116
  onClick={(event: MouseEvent<HTMLTableCellElement>) =>
@@ -91,10 +118,20 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
91
118
  }
92
119
  onDoubleClick={handleDoubleClick}
93
120
  {...tableCellProps}
94
- sx={{
121
+ sx={(theme) => ({
122
+ backgroundColor: column.getIsPinned()
123
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
124
+ : undefined,
125
+ boxShadow: getIsLastLeftPinnedColumn()
126
+ ? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
127
+ : getIsFirstRightPinnedColumn()
128
+ ? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
129
+ : undefined,
95
130
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
96
- maxWidth: `min(${column.getWidth()}px, fit-content)`,
97
- minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
131
+ left:
132
+ column.getIsPinned() === 'left'
133
+ ? `${column.getStart('left')}px`
134
+ : undefined,
98
135
  p: isDensePadding
99
136
  ? column.columnDefType === 'display'
100
137
  ? '0 0.5rem'
@@ -106,46 +143,63 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
106
143
  column.id === 'mrt-expand'
107
144
  ? `${row.depth + (isDensePadding ? 0.5 : 0.75)}rem`
108
145
  : undefined,
146
+ position: column.getIsPinned() ? 'sticky' : 'relative',
147
+ right:
148
+ column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
109
149
  transition: 'all 0.2s ease-in-out',
110
- whiteSpace:
111
- isDensePadding || (enablePinning && getIsSomeColumnsPinned())
112
- ? 'nowrap'
113
- : 'normal',
114
- width: column.getWidth(),
115
- //@ts-ignore
116
- ...tableCellProps?.sx,
150
+ whiteSpace: isDensePadding ? 'nowrap' : 'normal',
151
+ zIndex: column.getIsPinned() ? 1 : undefined,
152
+ '&:hover': {
153
+ backgroundColor: enableHover
154
+ ? theme.palette.mode === 'dark'
155
+ ? `${lighten(theme.palette.background.default, 0.13)} !important`
156
+ : `${darken(theme.palette.background.default, 0.07)} !important`
157
+ : undefined,
158
+ },
159
+ ...(tableCellProps?.sx as any),
160
+ })}
161
+ style={{
162
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
163
+ minWidth: `max(${column.getSize()}px, ${column.minSize ?? 30}px)`,
164
+ width: column.getSize(),
117
165
  }}
118
166
  >
119
- {isLoading ? (
120
- <Skeleton
121
- animation="wave"
122
- height={20}
123
- width={skeletonWidth}
124
- {...muiTableBodyCellSkeletonProps}
125
- />
126
- ) : column.columnDefType === 'display' ? (
127
- column.Cell?.({ cell, tableInstance })
128
- ) : cell.getIsPlaceholder() ||
129
- (row.getIsGrouped() &&
130
- column.id !==
131
- row.groupingColumnId) ? null : cell.getIsAggregated() ? (
132
- cell.renderAggregatedCell()
133
- ) : isEditing ? (
134
- <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
135
- ) : (enableClickToCopy || column.enableClickToCopy) &&
136
- column.enableClickToCopy !== false ? (
137
- <>
138
- <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
139
- {cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
140
- </MRT_CopyButton>
141
- {row.getIsGrouped() && <> ({row.subRows?.length})</>}
142
- </>
143
- ) : (
144
- <>
145
- {cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
146
- {row.getIsGrouped() && <> ({row.subRows?.length})</>}
147
- </>
148
- )}
167
+ <>
168
+ {isLoading || showSkeletons ? (
169
+ <Skeleton
170
+ animation="wave"
171
+ height={20}
172
+ width={skeletonWidth}
173
+ {...muiTableBodyCellSkeletonProps}
174
+ />
175
+ ) : column.columnDefType === 'display' ? (
176
+ column.columnDef.Cell?.({ cell, tableInstance })
177
+ ) : cell.getIsPlaceholder() ||
178
+ (row.getIsGrouped() &&
179
+ column.id !==
180
+ row.groupingColumnId) ? null : cell.getIsAggregated() ? (
181
+ cell.renderAggregatedCell()
182
+ ) : isEditing ? (
183
+ <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
184
+ ) : (enableClickToCopy || column.enableClickToCopy) &&
185
+ column.enableClickToCopy !== false ? (
186
+ <>
187
+ <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
188
+ <>
189
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ??
190
+ cell.renderCell()}
191
+ </>
192
+ </MRT_CopyButton>
193
+ {row.getIsGrouped() && <> ({row.subRows?.length})</>}
194
+ </>
195
+ ) : (
196
+ <>
197
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ??
198
+ cell.renderCell()}
199
+ {row.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
200
+ </>
201
+ )}
202
+ </>
149
203
  </TableCell>
150
204
  );
151
205
  };
@@ -1,47 +1,24 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { TableRow } from '@mui/material';
2
+ import { darken, lighten, TableRow } from '@mui/material';
3
3
  import { MRT_TableBodyCell } from './MRT_TableBodyCell';
4
4
  import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
5
5
  import type { MRT_Row, MRT_TableInstance } from '..';
6
6
 
7
7
  interface Props {
8
- pinned: 'left' | 'center' | 'right' | 'none';
9
8
  row: MRT_Row;
10
9
  tableInstance: MRT_TableInstance;
11
10
  }
12
11
 
13
- export const MRT_TableBodyRow: FC<Props> = ({ pinned, row, tableInstance }) => {
12
+ export const MRT_TableBodyRow: FC<Props> = ({ row, tableInstance }) => {
14
13
  const {
15
14
  options: { muiTableBodyRowProps, onRowClick, renderDetailPanel },
16
15
  } = tableInstance;
17
16
 
18
- const {
19
- getCenterVisibleCells,
20
- getIsGrouped,
21
- getIsSelected,
22
- getLeftVisibleCells,
23
- getRightVisibleCells,
24
- getRowProps,
25
- getVisibleCells,
26
- } = row;
27
-
28
- const mTableBodyRowProps =
17
+ const tableRowProps =
29
18
  muiTableBodyRowProps instanceof Function
30
19
  ? muiTableBodyRowProps({ row, tableInstance })
31
20
  : muiTableBodyRowProps;
32
21
 
33
- const tableRowProps = {
34
- ...getRowProps(),
35
- ...mTableBodyRowProps,
36
- };
37
-
38
- const getVisibleCellsMap = {
39
- center: getCenterVisibleCells,
40
- left: getLeftVisibleCells,
41
- none: getVisibleCells,
42
- right: getRightVisibleCells,
43
- };
44
-
45
22
  return (
46
23
  <>
47
24
  <TableRow
@@ -49,18 +26,32 @@ export const MRT_TableBodyRow: FC<Props> = ({ pinned, row, tableInstance }) => {
49
26
  onClick={(event: MouseEvent<HTMLTableRowElement>) =>
50
27
  onRowClick?.({ event, row, tableInstance })
51
28
  }
52
- selected={getIsSelected()}
29
+ selected={row.getIsSelected()}
53
30
  {...tableRowProps}
31
+ sx={(theme) => ({
32
+ backgroundColor: lighten(theme.palette.background.default, 0.06),
33
+ transition: 'all 0.2s ease-in-out',
34
+ '&:hover td': {
35
+ backgroundColor:
36
+ tableRowProps?.hover !== false
37
+ ? theme.palette.mode === 'dark'
38
+ ? `${lighten(theme.palette.background.default, 0.12)}`
39
+ : `${darken(theme.palette.background.default, 0.05)}`
40
+ : undefined,
41
+ },
42
+ ...(tableRowProps?.sx as any),
43
+ })}
54
44
  >
55
- {getVisibleCellsMap[pinned]().map((cell) => (
45
+ {row.getVisibleCells().map((cell) => (
56
46
  <MRT_TableBodyCell
57
47
  cell={cell}
58
- key={cell.getCellProps().key}
48
+ key={cell.id}
49
+ enableHover={tableRowProps?.hover !== false}
59
50
  tableInstance={tableInstance}
60
51
  />
61
52
  ))}
62
53
  </TableRow>
63
- {renderDetailPanel && !getIsGrouped() && (
54
+ {renderDetailPanel && !row.getIsGrouped() && (
64
55
  <MRT_TableDetailPanel row={row} tableInstance={tableInstance} />
65
56
  )}
66
57
  </>