material-react-table 1.6.2 → 1.6.4

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.
@@ -106,6 +106,8 @@ export declare const getLeadingDisplayColumnIds: <TData extends Record<string, a
106
106
  export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => (string | false | undefined)[];
107
107
  export declare const getDefaultColumnOrderIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => string[];
108
108
  export declare const getDefaultColumnFilterFn: <TData extends Record<string, any> = {}>(columnDef: MRT_ColumnDef<TData>) => MRT_FilterOption;
109
+ export declare const getIsFirstColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
110
+ export declare const getIsLastColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
109
111
  export declare const getIsLastLeftPinnedColumn: (table: MRT_TableInstance, column: MRT_Column) => boolean;
110
112
  export declare const getIsFirstRightPinnedColumn: (column: MRT_Column) => boolean;
111
113
  export declare const getTotalRight: (table: MRT_TableInstance, column: MRT_Column) => number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.2",
2
+ "version": "1.6.4",
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.",
@@ -35,7 +35,9 @@ export const MRT_TableBody: FC<Props> = ({
35
35
  enableRowVirtualization,
36
36
  layoutMode,
37
37
  localization,
38
+ manualExpanding,
38
39
  manualFiltering,
40
+ manualGrouping,
39
41
  manualPagination,
40
42
  manualSorting,
41
43
  memoMode,
@@ -47,8 +49,15 @@ export const MRT_TableBody: FC<Props> = ({
47
49
  },
48
50
  refs: { tableContainerRef, tablePaperRef },
49
51
  } = table;
50
- const { columnFilters, density, globalFilter, pagination, sorting } =
51
- getState();
52
+ const {
53
+ columnFilters,
54
+ density,
55
+ expanded,
56
+ globalFilter,
57
+ globalFilterFn,
58
+ pagination,
59
+ sorting,
60
+ } = getState();
52
61
 
53
62
  const tableBodyProps =
54
63
  muiTableBodyProps instanceof Function
@@ -65,30 +74,43 @@ export const MRT_TableBody: FC<Props> = ({
65
74
  ? rowVirtualizerProps({ table })
66
75
  : rowVirtualizerProps;
67
76
 
68
- const rows = useMemo(() => {
69
- if (
70
- enableGlobalFilterRankedResults &&
71
- globalFilter &&
77
+ const shouldRankResults = useMemo(
78
+ () =>
79
+ !manualExpanding &&
72
80
  !manualFiltering &&
81
+ !manualGrouping &&
73
82
  !manualSorting &&
74
- !Object.values(sorting).some(Boolean)
75
- ) {
76
- const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
77
- rankGlobalFuzzy(a, b),
78
- );
79
- if (enablePagination && !manualPagination) {
80
- const start = pagination.pageIndex * pagination.pageSize;
81
- return rankedRows.slice(start, start + pagination.pageSize);
82
- }
83
- return rankedRows;
83
+ enableGlobalFilterRankedResults &&
84
+ globalFilter &&
85
+ globalFilterFn === 'fuzzy' &&
86
+ expanded !== true &&
87
+ !Object.values(sorting).some(Boolean) &&
88
+ !Object.values(expanded).some(Boolean),
89
+ [
90
+ enableGlobalFilterRankedResults,
91
+ expanded,
92
+ globalFilter,
93
+ manualExpanding,
94
+ manualFiltering,
95
+ manualGrouping,
96
+ manualSorting,
97
+ sorting,
98
+ ],
99
+ );
100
+
101
+ const rows = useMemo(() => {
102
+ if (!shouldRankResults) return getRowModel().rows;
103
+ const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
104
+ rankGlobalFuzzy(a, b),
105
+ );
106
+ if (enablePagination && !manualPagination) {
107
+ const start = pagination.pageIndex * pagination.pageSize;
108
+ return rankedRows.slice(start, start + pagination.pageSize);
84
109
  }
85
- return getRowModel().rows;
110
+ return rankedRows;
86
111
  }, [
87
- enableGlobalFilterRankedResults,
88
- (enableGlobalFilterRankedResults && globalFilter) || !enablePagination
89
- ? getPrePaginationRowModel().rows
90
- : getRowModel().rows,
91
- globalFilter,
112
+ shouldRankResults,
113
+ shouldRankResults ? getPrePaginationRowModel().rows : getRowModel().rows,
92
114
  pagination.pageIndex,
93
115
  pagination.pageSize,
94
116
  ]);
@@ -15,7 +15,11 @@ import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
15
15
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
16
16
  import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
17
17
  import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
18
- import { getCommonCellStyles } from '../column.utils';
18
+ import {
19
+ getCommonCellStyles,
20
+ getIsFirstColumn,
21
+ getIsLastColumn,
22
+ } from '../column.utils';
19
23
  import type { VirtualItem } from '@tanstack/react-virtual';
20
24
  import type { MRT_Cell, MRT_TableInstance } from '..';
21
25
 
@@ -61,9 +65,11 @@ export const MRT_TableBodyCell: FC<Props> = ({
61
65
  } = table;
62
66
  const {
63
67
  draggingColumn,
68
+ draggingRow,
64
69
  editingCell,
65
70
  editingRow,
66
71
  hoveredColumn,
72
+ hoveredRow,
67
73
  density,
68
74
  isLoading,
69
75
  showSkeletons,
@@ -108,27 +114,44 @@ export const MRT_TableBodyCell: FC<Props> = ({
108
114
  [],
109
115
  );
110
116
 
111
- const draggingBorder = useMemo(
112
- () =>
113
- draggingColumn?.id === column.id
114
- ? `1px dashed ${theme.palette.text.secondary}`
115
- : hoveredColumn?.id === column.id
116
- ? `2px dashed ${theme.palette.primary.main}`
117
- : undefined,
118
- [draggingColumn, hoveredColumn],
119
- );
117
+ const draggingBorders = useMemo(() => {
118
+ const isDraggingColumn = draggingColumn?.id === column.id;
119
+ const isHoveredColumn = hoveredColumn?.id === column.id;
120
+ const isDraggingRow = draggingRow?.id === row.id;
121
+ const isHoveredRow = hoveredRow?.id === row.id;
122
+ const isFirstColumn = getIsFirstColumn(column, table);
123
+ const isLastColumn = getIsLastColumn(column, table);
124
+ const isLastRow = rowIndex === numRows - 1;
120
125
 
121
- const draggingBorders = useMemo(
122
- () =>
123
- draggingBorder
124
- ? {
125
- borderLeft: draggingBorder,
126
- borderRight: draggingBorder,
127
- borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
128
- }
129
- : undefined,
130
- [draggingBorder, numRows],
131
- );
126
+ const borderStyle =
127
+ isDraggingColumn || isDraggingRow
128
+ ? `1px dashed ${theme.palette.text.secondary} !important`
129
+ : isHoveredColumn || isHoveredRow
130
+ ? `2px dashed ${theme.palette.primary.main} !important`
131
+ : undefined;
132
+
133
+ return borderStyle
134
+ ? {
135
+ borderLeft:
136
+ isDraggingColumn ||
137
+ isHoveredColumn ||
138
+ ((isDraggingRow || isHoveredRow) && isFirstColumn)
139
+ ? borderStyle
140
+ : undefined,
141
+ borderRight:
142
+ isDraggingColumn ||
143
+ isHoveredColumn ||
144
+ ((isDraggingRow || isHoveredRow) && isLastColumn)
145
+ ? borderStyle
146
+ : undefined,
147
+ borderBottom:
148
+ isDraggingRow || isHoveredRow || isLastRow
149
+ ? borderStyle
150
+ : undefined,
151
+ borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
152
+ }
153
+ : undefined;
154
+ }, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
132
155
 
133
156
  const isEditable =
134
157
  (enableEditing || columnDef.enableEditing) &&
@@ -1,6 +1,6 @@
1
- import React, { DragEvent, FC, memo, useMemo, useRef } from 'react';
1
+ import React, { DragEvent, FC, memo, useRef } from 'react';
2
2
  import TableRow from '@mui/material/TableRow';
3
- import { darken, lighten, useTheme } from '@mui/material/styles';
3
+ import { darken, lighten } from '@mui/material/styles';
4
4
  import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
5
5
  import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
6
6
  import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
@@ -31,7 +31,6 @@ export const MRT_TableBodyRow: FC<Props> = ({
31
31
  virtualPaddingRight,
32
32
  virtualRow,
33
33
  }) => {
34
- const theme = useTheme();
35
34
  const {
36
35
  getIsSomeColumnsPinned,
37
36
  getState,
@@ -60,22 +59,6 @@ export const MRT_TableBodyRow: FC<Props> = ({
60
59
 
61
60
  const rowRef = useRef<HTMLTableRowElement | null>(null);
62
61
 
63
- const draggingBorder = useMemo(
64
- () =>
65
- draggingRow?.id === row.id
66
- ? `1px dashed ${theme.palette.text.secondary}`
67
- : hoveredRow?.id === row.id
68
- ? `2px dashed ${theme.palette.primary.main}`
69
- : undefined,
70
- [draggingRow, hoveredRow],
71
- );
72
-
73
- const draggingBorders = draggingBorder
74
- ? {
75
- border: draggingBorder,
76
- }
77
- : undefined;
78
-
79
62
  return (
80
63
  <>
81
64
  <TableRow
@@ -113,7 +96,6 @@ export const MRT_TableBodyRow: FC<Props> = ({
113
96
  ...(tableRowProps?.sx instanceof Function
114
97
  ? tableRowProps.sx(theme)
115
98
  : (tableRowProps?.sx as any)),
116
- ...draggingBorders,
117
99
  })}
118
100
  >
119
101
  {virtualPaddingLeft ? (
@@ -205,6 +205,21 @@ export const getDefaultColumnFilterFn = <
205
205
  return 'fuzzy';
206
206
  };
207
207
 
208
+ export const getIsFirstColumn = (
209
+ column: MRT_Column,
210
+ table: MRT_TableInstance,
211
+ ) => {
212
+ return table.getVisibleLeafColumns()[0].id === column.id;
213
+ };
214
+
215
+ export const getIsLastColumn = (
216
+ column: MRT_Column,
217
+ table: MRT_TableInstance,
218
+ ) => {
219
+ const columns = table.getVisibleLeafColumns();
220
+ return columns[columns.length - 1].id === column.id;
221
+ };
222
+
208
223
  export const getIsLastLeftPinnedColumn = (
209
224
  table: MRT_TableInstance,
210
225
  column: MRT_Column,