material-react-table 0.7.5 → 0.8.0-alpha.2

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 (55) hide show
  1. package/dist/MaterialReactTable.d.ts +16 -15
  2. package/dist/body/MRT_TableBody.d.ts +0 -1
  3. package/dist/body/MRT_TableBodyCell.d.ts +1 -0
  4. package/dist/body/MRT_TableBodyRow.d.ts +0 -1
  5. package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
  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 +7 -2
  14. package/dist/material-react-table.cjs.development.js +451 -418
  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 +454 -421
  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_ToolbarTop.d.ts +1 -0
  22. package/dist/utils.d.ts +1 -1
  23. package/package.json +21 -25
  24. package/src/MaterialReactTable.tsx +20 -24
  25. package/src/body/MRT_TableBody.tsx +3 -11
  26. package/src/body/MRT_TableBodyCell.tsx +103 -52
  27. package/src/body/MRT_TableBodyRow.tsx +21 -30
  28. package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
  29. package/src/buttons/MRT_CopyButton.tsx +3 -2
  30. package/src/buttons/MRT_EditActionButtons.tsx +1 -2
  31. package/src/buttons/MRT_ExpandAllButton.tsx +22 -18
  32. package/src/buttons/MRT_ExpandButton.tsx +27 -21
  33. package/src/enums.ts +2 -2
  34. package/src/filtersFNs.ts +71 -81
  35. package/src/footer/MRT_TableFooter.tsx +6 -16
  36. package/src/footer/MRT_TableFooterCell.tsx +15 -15
  37. package/src/footer/MRT_TableFooterRow.tsx +6 -8
  38. package/src/head/MRT_TableHead.tsx +5 -16
  39. package/src/head/MRT_TableHeadCell.tsx +116 -49
  40. package/src/head/MRT_TableHeadRow.tsx +8 -15
  41. package/src/inputs/MRT_EditCellTextField.tsx +3 -3
  42. package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
  43. package/src/inputs/MRT_FilterTextField.tsx +76 -41
  44. package/src/inputs/MRT_SelectCheckbox.tsx +15 -17
  45. package/src/localization.ts +15 -5
  46. package/src/menus/MRT_ColumnActionMenu.tsx +13 -12
  47. package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
  48. package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
  49. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +16 -6
  50. package/src/table/MRT_Table.tsx +8 -19
  51. package/src/table/MRT_TableContainer.tsx +8 -69
  52. package/src/table/MRT_TableRoot.tsx +44 -52
  53. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
  54. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
  55. package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
@@ -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>;
@@ -8,6 +8,7 @@ export declare const commonToolbarStyles: ({ theme }: {
8
8
  backgroundImage: string;
9
9
  display: string;
10
10
  p: string;
11
+ transition: string;
11
12
  width: string;
12
13
  zIndex: number;
13
14
  };
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,5 +1,5 @@
1
1
  {
2
- "version": "0.7.5",
2
+ "version": "0.8.0-alpha.2",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
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.",
@@ -55,39 +55,35 @@
55
55
  }
56
56
  ],
57
57
  "devDependencies": {
58
- "@babel/core": "^7.17.9",
58
+ "@babel/core": "^7.18.2",
59
59
  "@emotion/react": "^11.9.0",
60
60
  "@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.2",
61
+ "@faker-js/faker": "^6.3.1",
62
+ "@mui/icons-material": "^5.8.0",
63
+ "@mui/material": "^5.8.1",
65
64
  "@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",
65
+ "@storybook/addon-a11y": "^6.5.5",
66
+ "@storybook/addon-actions": "^6.5.5",
67
+ "@storybook/addon-essentials": "^6.5.5",
70
68
  "@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",
69
+ "@storybook/addon-links": "^6.5.5",
70
+ "@storybook/addons": "^6.5.5",
71
+ "@storybook/react": "^6.5.5",
72
+ "@types/react": "^18.0.9",
73
+ "@types/react-dom": "^18.0.5",
77
74
  "babel-loader": "^8.2.5",
78
- "eslint": "^8.14.0",
79
- "eslint-plugin-react-hooks": "^4.4.0",
80
- "husky": "^7.0.4",
75
+ "eslint": "^8.16.0",
76
+ "eslint-plugin-react-hooks": "^4.5.0",
77
+ "husky": "^8.0.1",
81
78
  "prettier": "^2.6.2",
82
79
  "react": "^17.0.2",
83
80
  "react-dom": "^17.0.2",
84
- "react-is": "^17.0.2",
81
+ "react-is": "^18.1.0",
85
82
  "size-limit": "^7.0.8",
86
- "storybook-addon-paddings": "^4.3.0",
87
- "storybook-dark-mode": "^1.0.9",
83
+ "storybook-dark-mode": "^1.1.0",
88
84
  "tsdx": "^0.14.1",
89
85
  "tslib": "^2.4.0",
90
- "typescript": "^4.6.3"
86
+ "typescript": "^4.7.2"
91
87
  },
92
88
  "peerDependencies": {
93
89
  "@emotion/react": ">=11",
@@ -97,7 +93,7 @@
97
93
  "react": ">=16.8"
98
94
  },
99
95
  "dependencies": {
100
- "@tanstack/react-table": "^8.0.0-alpha.47",
101
- "match-sorter": "^6.3.1"
96
+ "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
97
+ "@tanstack/react-table": "^8.0.0-beta.2"
102
98
  }
103
99
  }
@@ -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
  }
@@ -100,11 +101,11 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
100
101
  idPrefix: string;
101
102
  localization: MRT_Localization;
102
103
  };
103
- setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
104
- setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
104
+ setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
105
+ setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
105
106
  setCurrentFilterFns: Dispatch<
106
107
  SetStateAction<{
107
- [key: string]: MRT_FilterFn<D>;
108
+ [key: string]: MRT_FilterFn;
108
109
  }>
109
110
  >;
110
111
  setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
@@ -123,10 +124,13 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
123
124
  currentFilterFns: Record<string, string | Function>;
124
125
  currentGlobalFilterFn: Record<string, string | Function>;
125
126
  isDensePadding: boolean;
127
+ isLoading: boolean;
126
128
  isFullScreen: boolean;
129
+ pagination: Partial<PaginationState>;
127
130
  showFilters: boolean;
128
131
  showGlobalFilter: boolean;
129
- pagination: Partial<PaginationState>;
132
+ showProgressBars: boolean;
133
+ showSkeletons: boolean;
130
134
  };
131
135
 
132
136
  export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
@@ -276,6 +280,9 @@ export type MRT_Column<D extends Record<string, any> = {}> = Omit<
276
280
  > &
277
281
  MRT_ColumnDef<D> & {
278
282
  columns?: MRT_Column<D>[];
283
+ columnDef: MRT_ColumnDef<D>;
284
+ header: string;
285
+ footer: string;
279
286
  };
280
287
 
281
288
  export type MRT_Header<D extends Record<string, any> = {}> = Omit<
@@ -294,18 +301,9 @@ export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
294
301
 
295
302
  export type MRT_Row<D extends Record<string, any> = {}> = Omit<
296
303
  Row<D>,
297
- | 'getVisibleCells'
298
- | 'getAllCells'
299
- | 'subRows'
300
- | 'original'
301
- | 'getLeftVisibleCells'
302
- | 'getRightVisibleCells'
303
- | 'getCenterVisibleCells'
304
+ 'getVisibleCells' | 'getAllCells' | 'subRows' | 'original'
304
305
  > & {
305
306
  getAllCells: () => MRT_Cell<D>[];
306
- getCenterVisibleCells: () => MRT_Cell<D>[];
307
- getLeftVisibleCells: () => MRT_Cell<D>[];
308
- getRightVisibleCells: () => MRT_Cell<D>[];
309
307
  getVisibleCells: () => MRT_Cell<D>[];
310
308
  subRows?: MRT_Row<D>[];
311
309
  original: D;
@@ -320,7 +318,7 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
320
318
  };
321
319
 
322
320
  export type MRT_FilterFn<D extends Record<string, any> = {}> =
323
- | FilterFn<D>
321
+ | FilterFn<TableGenerics>
324
322
  | FilterFnOption<D>
325
323
  | MRT_FILTER_OPTION
326
324
  | number
@@ -351,8 +349,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
351
349
  enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
352
350
  icons?: Partial<MRT_Icons>;
353
351
  idPrefix?: string;
354
- isLoading?: boolean;
355
- isReloading?: boolean;
356
352
  localization?: Partial<MRT_Localization>;
357
353
  muiLinearProgressProps?:
358
354
  | LinearProgressProps
@@ -760,7 +756,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
760
756
 
761
757
  export default <D extends Record<string, any> = {}>({
762
758
  autoResetExpanded = false,
763
- autoResetSorting = false,
764
759
  columnResizeMode = 'onEnd',
765
760
  editingMode = 'row',
766
761
  enableColumnActions = true,
@@ -774,6 +769,7 @@ export default <D extends Record<string, any> = {}>({
774
769
  enableHiding = true,
775
770
  enableMultiRowSelection = true,
776
771
  enablePagination = true,
772
+ enablePinning = false,
777
773
  enableSelectAll = true,
778
774
  enableSorting = true,
779
775
  enableStickyHeader = true,
@@ -793,12 +789,11 @@ export default <D extends Record<string, any> = {}>({
793
789
  }: MaterialReactTableProps<D>) => (
794
790
  <MRT_TableRoot
795
791
  autoResetExpanded={autoResetExpanded}
796
- autoResetSorting={autoResetSorting}
797
792
  columnResizeMode={columnResizeMode}
798
793
  editingMode={editingMode}
799
794
  enableColumnActions={enableColumnActions}
800
- enableColumnResizing={enableColumnResizing}
801
795
  enableColumnFilters={enableColumnFilters}
796
+ enableColumnResizing={enableColumnResizing}
802
797
  enableDensePaddingToggle={enableDensePaddingToggle}
803
798
  enableExpandAll={enableExpandAll}
804
799
  enableFilters={enableFilters}
@@ -807,6 +802,7 @@ export default <D extends Record<string, any> = {}>({
807
802
  enableHiding={enableHiding}
808
803
  enableMultiRowSelection={enableMultiRowSelection}
809
804
  enablePagination={enablePagination}
805
+ enablePinning={enablePinning}
810
806
  enableSelectAll={enableSelectAll}
811
807
  enableSorting={enableSorting}
812
808
  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,22 @@ 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,
135
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
136
+ minWidth: `max${column.getSize()}px, ${column.minSize}px`,
98
137
  p: isDensePadding
99
138
  ? column.columnDefType === 'display'
100
139
  ? '0 0.5rem'
@@ -106,46 +145,58 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
106
145
  column.id === 'mrt-expand'
107
146
  ? `${row.depth + (isDensePadding ? 0.5 : 0.75)}rem`
108
147
  : undefined,
148
+ position: column.getIsPinned() ? 'sticky' : 'relative',
149
+ right:
150
+ column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
109
151
  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,
117
- }}
152
+ whiteSpace: isDensePadding ? 'nowrap' : 'normal',
153
+ width: column.getSize(),
154
+ zIndex: column.getIsPinned() ? 1 : undefined,
155
+ '&:hover': {
156
+ backgroundColor: enableHover
157
+ ? theme.palette.mode === 'dark'
158
+ ? `${lighten(theme.palette.background.default, 0.13)} !important`
159
+ : `${darken(theme.palette.background.default, 0.07)} !important`
160
+ : undefined,
161
+ },
162
+ ...(tableCellProps?.sx as any),
163
+ })}
118
164
  >
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
- )}
165
+ <>
166
+ {isLoading || showSkeletons ? (
167
+ <Skeleton
168
+ animation="wave"
169
+ height={20}
170
+ width={skeletonWidth}
171
+ {...muiTableBodyCellSkeletonProps}
172
+ />
173
+ ) : column.columnDefType === 'display' ? (
174
+ column.columnDef.Cell?.({ cell, tableInstance })
175
+ ) : cell.getIsPlaceholder() ||
176
+ (row.getIsGrouped() &&
177
+ column.id !==
178
+ row.groupingColumnId) ? null : cell.getIsAggregated() ? (
179
+ cell.renderAggregatedCell()
180
+ ) : isEditing ? (
181
+ <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
182
+ ) : (enableClickToCopy || column.enableClickToCopy) &&
183
+ column.enableClickToCopy !== false ? (
184
+ <>
185
+ <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
186
+ <>
187
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ??
188
+ cell.renderCell()}
189
+ </>
190
+ </MRT_CopyButton>
191
+ {row.getIsGrouped() && <> ({row.subRows?.length})</>}
192
+ </>
193
+ ) : (
194
+ <>
195
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
196
+ {row.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
197
+ </>
198
+ )}
199
+ </>
149
200
  </TableCell>
150
201
  );
151
202
  };
@@ -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
  </>
@@ -0,0 +1,57 @@
1
+ import React, { FC } from 'react';
2
+ import { Box, IconButton, Tooltip } from '@mui/material';
3
+ import type { MRT_Column, MRT_TableInstance } from '..';
4
+
5
+ interface Props {
6
+ column: MRT_Column;
7
+ tableInstance: MRT_TableInstance;
8
+ }
9
+
10
+ export const MRT_ColumnPinningButtons: FC<Props> = ({
11
+ column,
12
+ tableInstance,
13
+ }) => {
14
+ const {
15
+ options: {
16
+ icons: { PushPinIcon },
17
+ localization,
18
+ },
19
+ } = tableInstance;
20
+
21
+ const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
22
+ column.pin(pinDirection);
23
+ };
24
+
25
+ return (
26
+ <Box sx={{ mr: '8px' }}>
27
+ {column.getIsPinned() ? (
28
+ <Tooltip arrow title={localization.unpin}>
29
+ <IconButton onClick={() => handlePinColumn(false)} size="small">
30
+ <PushPinIcon />
31
+ </IconButton>
32
+ </Tooltip>
33
+ ) : (
34
+ <>
35
+ <Tooltip arrow title={localization.pinToLeft}>
36
+ <IconButton onClick={() => handlePinColumn('left')} size="small">
37
+ <PushPinIcon
38
+ style={{
39
+ transform: 'rotate(90deg)',
40
+ }}
41
+ />
42
+ </IconButton>
43
+ </Tooltip>
44
+ <Tooltip arrow title={localization.pinToRight}>
45
+ <IconButton onClick={() => handlePinColumn('right')} size="small">
46
+ <PushPinIcon
47
+ style={{
48
+ transform: 'rotate(-90deg)',
49
+ }}
50
+ />
51
+ </IconButton>
52
+ </Tooltip>
53
+ </>
54
+ )}
55
+ </Box>
56
+ );
57
+ };