material-react-table 1.0.0-beta.3 → 1.0.0-beta.6

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.
@@ -1,7 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
- stackAlertBanner?: boolean;
4
+ stackAlertBanner: boolean;
5
5
  table: MRT_TableInstance;
6
6
  }
7
7
  export declare const MRT_ToolbarAlertBanner: FC<Props>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
1
+ import { MutableRefObject, Dispatch, SetStateAction, ReactNode } from 'react';
2
2
  import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
3
3
  import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
4
4
  import { Options, VirtualItem } from 'react-virtual';
@@ -154,6 +154,8 @@ interface MRT_Localization {
154
154
  max: string;
155
155
  min: string;
156
156
  move: string;
157
+ noRecordsToDisplay: string;
158
+ noResultsFound: string;
157
159
  or: string;
158
160
  pinToLeft: string;
159
161
  pinToRight: string;
@@ -231,6 +233,7 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
231
233
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
232
234
  searchInputRef: MutableRefObject<HTMLInputElement>;
233
235
  tableContainerRef: MutableRefObject<HTMLDivElement>;
236
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
234
237
  topToolbarRef: MutableRefObject<HTMLDivElement>;
235
238
  };
236
239
  setColumnFilterFns: Dispatch<SetStateAction<{
@@ -630,13 +633,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
630
633
  muiTopToolbarProps?: ToolbarProps | (({ table }: {
631
634
  table: MRT_TableInstance<TData>;
632
635
  }) => ToolbarProps);
633
- onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
634
- event: DragEvent<HTMLButtonElement>;
635
- draggedColumn: MRT_Column<TData>;
636
- targetColumn: MRT_Column<TData> | {
637
- id: string;
638
- } | null;
639
- }) => void;
640
636
  onDensityChange?: OnChangeFn<boolean>;
641
637
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
642
638
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -655,13 +651,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
655
651
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
656
652
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
657
653
  onIsFullScreenChange?: OnChangeFn<boolean>;
658
- onRowDrop?: ({ event, draggedRow, targetRow, }: {
659
- event: DragEvent<HTMLButtonElement>;
660
- draggedRow: MRT_Row<TData>;
661
- targetRow: MRT_Row<TData> | {
662
- id: string;
663
- } | null;
664
- }) => void;
665
654
  onShowAlertBannerChange?: OnChangeFn<boolean>;
666
655
  onShowFiltersChange?: OnChangeFn<boolean>;
667
656
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.3",
2
+ "version": "1.0.0-beta.6",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -1,6 +1,5 @@
1
1
  import React, {
2
2
  Dispatch,
3
- DragEvent,
4
3
  MutableRefObject,
5
4
  ReactNode,
6
5
  SetStateAction,
@@ -101,6 +100,7 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
101
100
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
102
101
  searchInputRef: MutableRefObject<HTMLInputElement>;
103
102
  tableContainerRef: MutableRefObject<HTMLDivElement>;
103
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
104
104
  topToolbarRef: MutableRefObject<HTMLDivElement>;
105
105
  };
106
106
  setColumnFilterFns: Dispatch<
@@ -753,15 +753,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
753
753
  muiTopToolbarProps?:
754
754
  | ToolbarProps
755
755
  | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
756
- onColumnDrop?: ({
757
- event,
758
- draggedColumn,
759
- targetColumn,
760
- }: {
761
- event: DragEvent<HTMLButtonElement>;
762
- draggedColumn: MRT_Column<TData>;
763
- targetColumn: MRT_Column<TData> | { id: string } | null;
764
- }) => void;
765
756
  onDensityChange?: OnChangeFn<boolean>;
766
757
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
767
758
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -783,15 +774,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
783
774
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
784
775
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
785
776
  onIsFullScreenChange?: OnChangeFn<boolean>;
786
- onRowDrop?: ({
787
- event,
788
- draggedRow,
789
- targetRow,
790
- }: {
791
- event: DragEvent<HTMLButtonElement>;
792
- draggedRow: MRT_Row<TData>;
793
- targetRow: MRT_Row<TData> | { id: string } | null;
794
- }) => void;
795
777
  onShowAlertBannerChange?: OnChangeFn<boolean>;
796
778
  onShowFiltersChange?: OnChangeFn<boolean>;
797
779
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { useVirtual } from 'react-virtual'; //stuck on v2 for now
3
3
  // import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
4
- import { TableBody } from '@mui/material';
4
+ import { TableBody, Typography } from '@mui/material';
5
5
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
6
6
  import { rankGlobalFuzzy } from '../sortingFns';
7
7
  import type { MRT_Row, MRT_TableInstance } from '..';
@@ -19,15 +19,16 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
19
19
  enableGlobalFilterRankedResults,
20
20
  enablePagination,
21
21
  enableRowVirtualization,
22
+ localization,
22
23
  manualFiltering,
23
24
  manualSorting,
24
25
  muiTableBodyProps,
25
26
  virtualizerInstanceRef,
26
27
  virtualizerProps,
27
28
  },
28
- refs: { tableContainerRef },
29
+ refs: { tableContainerRef, tablePaperRef },
29
30
  } = table;
30
- const { globalFilter, pagination, sorting } = getState();
31
+ const { columnFilters, globalFilter, pagination, sorting } = getState();
31
32
 
32
33
  const tableBodyProps =
33
34
  muiTableBodyProps instanceof Function
@@ -116,33 +117,56 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
116
117
 
117
118
  return (
118
119
  <TableBody {...tableBodyProps}>
119
- {enableRowVirtualization && paddingTop > 0 && (
120
+ {!rows.length ? (
120
121
  <tr>
121
- <td style={{ height: `${paddingTop}px` }} />
122
- </tr>
123
- )}
124
- {(enableRowVirtualization ? virtualRows : rows).map(
125
- (rowOrVirtualRow: any, rowIndex: number) => {
126
- const row = enableRowVirtualization
127
- ? (rows[rowOrVirtualRow.index] as MRT_Row)
128
- : (rowOrVirtualRow as MRT_Row);
129
- return (
130
- <MRT_TableBodyRow
131
- key={row.id}
132
- row={row}
133
- rowIndex={
134
- enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
135
- }
136
- table={table}
137
- virtualRow={enableRowVirtualization ? rowOrVirtualRow : null}
138
- />
139
- );
140
- },
141
- )}
142
- {enableRowVirtualization && paddingBottom > 0 && (
143
- <tr>
144
- <td style={{ height: `${paddingBottom}px` }} />
122
+ <td colSpan={table.getVisibleLeafColumns().length}>
123
+ <Typography
124
+ sx={{
125
+ color: 'text.secondary',
126
+ fontStyle: 'italic',
127
+ maxWidth: `min(100vw, ${tablePaperRef.current?.clientWidth}px)`,
128
+ py: '2rem',
129
+ textAlign: 'center',
130
+ width: '100%',
131
+ }}
132
+ >
133
+ {globalFilter || columnFilters.length
134
+ ? localization.noResultsFound
135
+ : localization.noRecordsToDisplay}
136
+ </Typography>
137
+ </td>
145
138
  </tr>
139
+ ) : (
140
+ <>
141
+ {enableRowVirtualization && paddingTop > 0 && (
142
+ <tr>
143
+ <td style={{ height: `${paddingTop}px` }} />
144
+ </tr>
145
+ )}
146
+ {(enableRowVirtualization ? virtualRows : rows).map(
147
+ (rowOrVirtualRow: any, rowIndex: number) => {
148
+ const row = enableRowVirtualization
149
+ ? (rows[rowOrVirtualRow.index] as MRT_Row)
150
+ : (rowOrVirtualRow as MRT_Row);
151
+ return (
152
+ <MRT_TableBodyRow
153
+ key={row.id}
154
+ row={row}
155
+ rowIndex={
156
+ enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
157
+ }
158
+ table={table}
159
+ virtualRow={enableRowVirtualization ? rowOrVirtualRow : null}
160
+ />
161
+ );
162
+ },
163
+ )}
164
+ {enableRowVirtualization && paddingBottom > 0 && (
165
+ <tr>
166
+ <td style={{ height: `${paddingBottom}px` }} />
167
+ </tr>
168
+ )}
169
+ </>
146
170
  )}
147
171
  </TableBody>
148
172
  );
@@ -6,19 +6,13 @@ import React, {
6
6
  useEffect,
7
7
  useState,
8
8
  } from 'react';
9
- import {
10
- alpha,
11
- darken,
12
- lighten,
13
- Skeleton,
14
- TableCell,
15
- useTheme,
16
- } from '@mui/material';
9
+ import { darken, lighten, Skeleton, TableCell, useTheme } from '@mui/material';
17
10
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
18
11
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
19
- import type { MRT_Cell, MRT_TableInstance } from '..';
20
12
  import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
21
13
  import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
14
+ import { getCommonCellStyles } from '../column.utils';
15
+ import type { MRT_Cell, MRT_TableInstance } from '..';
22
16
 
23
17
  interface Props {
24
18
  cell: MRT_Cell;
@@ -132,23 +126,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
132
126
  }
133
127
  };
134
128
 
135
- const getIsLastLeftPinnedColumn = () => {
136
- return (
137
- column.getIsPinned() === 'left' &&
138
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
139
- );
140
- };
141
-
142
- const getIsFirstRightPinnedColumn = () => {
143
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
144
- };
145
-
146
- const getTotalRight = () => {
147
- return (
148
- (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
149
- );
150
- };
151
-
152
129
  const handleDragEnter = (e: DragEvent<HTMLTableCellElement>) => {
153
130
  tableCellProps?.onDragEnter?.(e);
154
131
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
@@ -190,23 +167,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
190
167
  onDragEnter={handleDragEnter}
191
168
  onDoubleClick={handleDoubleClick}
192
169
  sx={(theme) => ({
193
- backgroundColor: column.getIsPinned()
194
- ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
195
- : undefined,
196
- boxShadow: getIsLastLeftPinnedColumn()
197
- ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
198
- : getIsFirstRightPinnedColumn()
199
- ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
200
- : undefined,
201
170
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
202
- left:
203
- column.getIsPinned() === 'left'
204
- ? `${column.getStart('left')}px`
205
- : undefined,
206
- opacity:
207
- draggingColumn?.id === column.id || hoveredColumn?.id === column.id
208
- ? 0.5
209
- : 1,
210
171
  overflow: 'hidden',
211
172
  p:
212
173
  density === 'compact'
@@ -231,11 +192,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
231
192
  : 1.25)
232
193
  }rem`
233
194
  : undefined,
234
- position: column.getIsPinned() ? 'sticky' : 'relative',
235
- right:
236
- column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
237
195
  textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
238
- transition: 'all 0.2s ease-in-out',
239
196
  whiteSpace: density === 'compact' ? 'nowrap' : 'normal',
240
197
  zIndex:
241
198
  draggingColumn?.id === column.id ? 2 : column.getIsPinned() ? 1 : 0,
@@ -250,13 +207,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
250
207
  : `${darken(theme.palette.background.default, 0.1)} !important`
251
208
  : undefined,
252
209
  },
253
- ...(tableCellProps?.sx instanceof Function
254
- ? tableCellProps.sx(theme)
255
- : (tableCellProps?.sx as any)),
210
+ ...getCommonCellStyles({ column, table, theme, tableCellProps }),
256
211
  ...draggingBorders,
257
- maxWidth: `min(${column.getSize()}px, fit-content)`,
258
- minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
259
- width: column.getSize(),
260
212
  })}
261
213
  >
262
214
  <>
@@ -14,7 +14,7 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
14
14
  table,
15
15
  }) => {
16
16
  const {
17
- options: { muiTableBodyRowDragHandleProps, onRowDrop },
17
+ options: { muiTableBodyRowDragHandleProps },
18
18
  } = table;
19
19
  const { row } = cell;
20
20
 
@@ -23,17 +23,14 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
23
23
  ? muiTableBodyRowDragHandleProps({ row, table })
24
24
  : muiTableBodyRowDragHandleProps;
25
25
 
26
- const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
27
- e.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
26
+ const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
27
+ iconButtonProps?.onDragStart?.(event);
28
+ event.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
28
29
  table.setDraggingRow(row as any);
29
30
  };
30
31
 
31
32
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
32
- onRowDrop?.({
33
- event,
34
- draggedRow: table.getState().draggingRow as any,
35
- targetRow: table.getState().hoveredRow as any,
36
- });
33
+ iconButtonProps?.onDragEnd?.(event);
37
34
  table.setDraggingRow(null);
38
35
  table.setHoveredRow(null);
39
36
  };
@@ -33,14 +33,14 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
33
33
  <IconButton
34
34
  disableRipple
35
35
  draggable="true"
36
- onDragStart={onDragStart}
37
- onDragEnd={onDragEnd}
38
36
  size="small"
39
37
  {...iconButtonProps}
40
38
  onClick={(e) => {
41
39
  e.stopPropagation();
42
40
  iconButtonProps?.onClick?.(e);
43
41
  }}
42
+ onDragStart={onDragStart}
43
+ onDragEnd={onDragEnd}
44
44
  sx={(theme) => ({
45
45
  cursor: 'grab',
46
46
  m: 0,
@@ -1,4 +1,5 @@
1
1
  import { ColumnOrderState, GroupingState } from '@tanstack/react-table';
2
+ import { alpha, lighten, TableCellProps, Theme } from '@mui/material';
2
3
  import {
3
4
  MaterialReactTableProps,
4
5
  MRT_Column,
@@ -6,6 +7,8 @@ import {
6
7
  MRT_DefinedColumnDef,
7
8
  MRT_DisplayColumnIds,
8
9
  MRT_FilterOption,
10
+ MRT_Header,
11
+ MRT_TableInstance,
9
12
  } from '.';
10
13
  import { MRT_FilterFns } from './filterFns';
11
14
  import { MRT_SortingFns } from './sortingFns';
@@ -165,3 +168,72 @@ export const getDefaultColumnFilterFn = <
165
168
  if (columnDef.filterVariant === 'range') return 'betweenInclusive';
166
169
  return 'fuzzy';
167
170
  };
171
+
172
+ export const getIsLastLeftPinnedColumn = (
173
+ table: MRT_TableInstance,
174
+ column: MRT_Column,
175
+ ) => {
176
+ return (
177
+ column.getIsPinned() === 'left' &&
178
+ table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
179
+ );
180
+ };
181
+
182
+ export const getIsFirstRightPinnedColumn = (column: MRT_Column) => {
183
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
184
+ };
185
+
186
+ export const getTotalRight = (table: MRT_TableInstance, column: MRT_Column) => {
187
+ return (
188
+ (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
189
+ );
190
+ };
191
+
192
+ export const getCommonCellStyles = ({
193
+ column,
194
+ header,
195
+ table,
196
+ tableCellProps,
197
+ theme,
198
+ }: {
199
+ column: MRT_Column;
200
+ header?: MRT_Header;
201
+ table: MRT_TableInstance;
202
+ tableCellProps: TableCellProps;
203
+ theme: Theme;
204
+ }) => ({
205
+ backgroundColor:
206
+ column.getIsPinned() && column.columnDef.columnDefType !== 'group'
207
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
208
+ : 'inherit',
209
+ backgroundImage: 'inherit',
210
+ boxShadow: getIsLastLeftPinnedColumn(table, column)
211
+ ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
212
+ : getIsFirstRightPinnedColumn(column)
213
+ ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
214
+ : undefined,
215
+ left:
216
+ column.getIsPinned() === 'left'
217
+ ? `${column.getStart('left')}px`
218
+ : undefined,
219
+ opacity:
220
+ table.getState().draggingColumn?.id === column.id ||
221
+ table.getState().hoveredColumn?.id === column.id
222
+ ? 0.5
223
+ : 1,
224
+ position:
225
+ column.getIsPinned() && column.columnDef.columnDefType !== 'group'
226
+ ? 'sticky'
227
+ : undefined,
228
+ right:
229
+ column.getIsPinned() === 'right'
230
+ ? `${getTotalRight(table, column)}px`
231
+ : undefined,
232
+ transition: `all ${column.getIsResizing() ? 0 : '0.2s'} ease-in-out`,
233
+ ...(tableCellProps?.sx instanceof Function
234
+ ? tableCellProps.sx(theme)
235
+ : (tableCellProps?.sx as any)),
236
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
237
+ minWidth: `max(${column.getSize()}px, ${column.columnDef.minSize ?? 30}px)`,
238
+ width: header?.getSize() ?? column.getSize(),
239
+ });
@@ -1,5 +1,6 @@
1
1
  import React, { FC } from 'react';
2
- import { alpha, TableCell } from '@mui/material';
2
+ import { TableCell } from '@mui/material';
3
+ import { getCommonCellStyles } from '../column.utils';
3
4
  import type { MRT_Header, MRT_TableInstance } from '..';
4
5
 
5
6
  interface Props {
@@ -10,7 +11,7 @@ interface Props {
10
11
  export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
11
12
  const {
12
13
  getState,
13
- options: { muiTableFooterCellProps, enableColumnResizing },
14
+ options: { muiTableFooterCellProps },
14
15
  } = table;
15
16
  const { density } = getState();
16
17
  const { column } = footer;
@@ -39,26 +40,15 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
39
40
  variant="head"
40
41
  {...tableCellProps}
41
42
  sx={(theme) => ({
42
- backgroundColor: theme.palette.background.default,
43
- backgroundImage: `linear-gradient(${alpha(
44
- theme.palette.common.white,
45
- 0.05,
46
- )},${alpha(theme.palette.common.white, 0.05)})`,
47
43
  fontWeight: 'bold',
48
- maxWidth: `${column.getSize()}px`,
49
- minWidth: `${column.getSize()}px`,
50
44
  p:
51
45
  density === 'compact'
52
46
  ? '0.5rem'
53
47
  : density === 'comfortable'
54
48
  ? '1rem'
55
49
  : '1.5rem',
56
- transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
57
- width: column.getSize(),
58
- verticalAlign: 'text-top',
59
- ...(tableCellProps?.sx instanceof Function
60
- ? tableCellProps.sx(theme)
61
- : (tableCellProps?.sx as any)),
50
+ verticalAlign: 'top',
51
+ ...getCommonCellStyles({ column, table, theme, tableCellProps }),
62
52
  })}
63
53
  >
64
54
  <>
@@ -1,11 +1,12 @@
1
1
  import React, { DragEvent, FC, ReactNode } from 'react';
2
- import { Box, TableCell, Theme, alpha, lighten, useTheme } from '@mui/material';
2
+ import { Box, TableCell, Theme, useTheme } from '@mui/material';
3
3
  import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
4
4
  import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
5
5
  import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
6
6
  import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
7
7
  import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
8
8
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
9
+ import { getCommonCellStyles } from '../column.utils';
9
10
  import type { MRT_Header, MRT_TableInstance } from '..';
10
11
 
11
12
  interface Props {
@@ -21,7 +22,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
21
22
  enableColumnActions,
22
23
  enableColumnDragging,
23
24
  enableColumnOrdering,
24
- enableColumnResizing,
25
25
  enableGrouping,
26
26
  enableMultiSort,
27
27
  muiTableHeadCellProps,
@@ -54,23 +54,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
54
54
  ...mcTableHeadCellProps,
55
55
  };
56
56
 
57
- const getIsLastLeftPinnedColumn = () => {
58
- return (
59
- column.getIsPinned() === 'left' &&
60
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
61
- );
62
- };
63
-
64
- const getIsFirstRightPinnedColumn = () => {
65
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
66
- };
67
-
68
- const getTotalRight = () => {
69
- return (
70
- (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
71
- );
72
- };
73
-
74
57
  const handleDragEnter = (_e: DragEvent) => {
75
58
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
76
59
  setHoveredColumn(null);
@@ -115,26 +98,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
115
98
  ref={tableHeadCellRef}
116
99
  {...tableCellProps}
117
100
  sx={(theme: Theme) => ({
118
- backgroundColor:
119
- column.getIsPinned() && columnDefType !== 'group'
120
- ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
121
- : 'inherit',
122
- backgroundImage: 'inherit',
123
- boxShadow: getIsLastLeftPinnedColumn()
124
- ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
125
- : getIsFirstRightPinnedColumn()
126
- ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
127
- : undefined,
128
101
  fontWeight: 'bold',
129
- left:
130
- column.getIsPinned() === 'left'
131
- ? `${column.getStart('left')}px`
132
- : undefined,
133
102
  overflow: 'visible',
134
- opacity:
135
- draggingColumn?.id === column.id || hoveredColumn?.id === column.id
136
- ? 0.5
137
- : 1,
138
103
  p:
139
104
  density === 'compact'
140
105
  ? '0.5rem'
@@ -151,19 +116,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
151
116
  : showColumnFilters || density === 'compact'
152
117
  ? '0.4rem'
153
118
  : '0.6rem',
154
- position:
155
- column.getIsPinned() && columnDefType !== 'group'
156
- ? 'sticky'
157
- : undefined,
158
119
  pt:
159
120
  columnDefType === 'group' || density === 'compact'
160
121
  ? '0.25rem'
161
122
  : density === 'comfortable'
162
123
  ? '.75rem'
163
124
  : '1.25rem',
164
- right:
165
- column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
166
- transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
167
125
  userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
168
126
  verticalAlign: 'top',
169
127
  zIndex:
@@ -172,13 +130,14 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
172
130
  : column.getIsPinned() && columnDefType !== 'group'
173
131
  ? 2
174
132
  : 1,
175
- ...(tableCellProps?.sx instanceof Function
176
- ? tableCellProps.sx(theme)
177
- : (tableCellProps?.sx as any)),
133
+ ...getCommonCellStyles({
134
+ column,
135
+ header,
136
+ table,
137
+ tableCellProps,
138
+ theme,
139
+ }),
178
140
  ...draggingBorders,
179
- maxWidth: `min(${column.getSize()}px, fit-content)`,
180
- minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
181
- width: header.getSize(),
182
141
  })}
183
142
  >
184
143
  {header.isPlaceholder ? null : (
@@ -16,11 +16,7 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
16
16
  }) => {
17
17
  const {
18
18
  getState,
19
- options: {
20
- enableColumnOrdering,
21
- muiTableHeadCellDragHandleProps,
22
- onColumnDrop,
23
- },
19
+ options: { enableColumnOrdering, muiTableHeadCellDragHandleProps },
24
20
  setColumnOrder,
25
21
  setDraggingColumn,
26
22
  setHoveredColumn,
@@ -43,17 +39,14 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
43
39
  ...mcIconButtonProps,
44
40
  };
45
41
 
46
- const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
42
+ const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
43
+ iconButtonProps?.onDragStart?.(event);
47
44
  setDraggingColumn(column);
48
- e.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
45
+ event.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
49
46
  };
50
47
 
51
48
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
52
- onColumnDrop?.({
53
- event,
54
- draggedColumn: column,
55
- targetColumn: hoveredColumn,
56
- });
49
+ iconButtonProps?.onDragEnd?.(event);
57
50
  if (hoveredColumn?.id === 'drop-zone') {
58
51
  column.toggleGrouping();
59
52
  } else if (
@@ -47,6 +47,8 @@ export interface MRT_Localization {
47
47
  max: string;
48
48
  min: string;
49
49
  move: string;
50
+ noRecordsToDisplay: string;
51
+ noResultsFound: string;
50
52
  or: string;
51
53
  pinToLeft: string;
52
54
  pinToRight: string;
@@ -129,6 +131,8 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
129
131
  max: 'Max',
130
132
  min: 'Min',
131
133
  move: 'Move',
134
+ noRecordsToDisplay: 'No records to display',
135
+ noResultsFound: 'No results found',
132
136
  or: 'or',
133
137
  pinToLeft: 'Pin to left',
134
138
  pinToRight: 'Pin to right',