@@ -10,12 +10,16 @@ import { Tooltip } from '@material-ui/core';
10
10
import { withStyles } from '@material-ui/core/styles' ;
11
11
import * as CommonValues from '../../utils/common-values' ;
12
12
13
- export function MTableHeader ( { onColumnResized, ...props } ) {
13
+ export function MTableHeader ( { onColumnResized, columns , ...props } ) {
14
14
const defaultMinColumnWidth = 20 ;
15
15
const defaultMaxColumnWidth = 10000 ;
16
16
17
17
const [ resizing , setResizing ] = React . useState ( undefined ) ;
18
18
const [ lastX , setLastX ] = React . useState ( 0 ) ;
19
+ const displayingColumns = React . useMemo (
20
+ ( ) => columns . filter ( ( c ) => c . hidden !== true ) ,
21
+ [ columns ]
22
+ ) ;
19
23
20
24
const handleMouseDown = ( e , columnDef , colIndex ) => {
21
25
const startX = e . clientX ;
@@ -30,7 +34,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
30
34
nextWidth =
31
35
nextTh &&
32
36
Math . round ( + window . getComputedStyle ( nextTh ) . width . slice ( 0 , - 2 ) ) ;
33
- nextColIndex = props . columns . findIndex (
37
+ nextColIndex = displayingColumns . findIndex (
34
38
( c ) => c . tableData . id === columnDef . tableData . id + 1
35
39
) ;
36
40
} else if ( ! initialColWidths ) {
@@ -45,9 +49,9 @@ export function MTableHeader({ onColumnResized, ...props }) {
45
49
colIndex,
46
50
nextColIndex,
47
51
lastColData : { ...columnDef . tableData , width : currentWidth } ,
48
- ...( nextColIndex && {
52
+ ...( nextColIndex !== - 1 && {
49
53
lastNextColData : {
50
- ...props . columns [ nextColIndex ] . tableData ,
54
+ ...displayingColumns [ nextColIndex ] . tableData ,
51
55
width : nextWidth
52
56
}
53
57
} ) ,
@@ -80,7 +84,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
80
84
}
81
85
82
86
const curX = e . clientX ;
83
- const col = props . columns [ resizing . colIndex ] ;
87
+ const col = displayingColumns [ resizing . colIndex ] ;
84
88
const alreadyOffset =
85
89
col . tableData . additionalWidth - resizing . lastColData . additionalWidth ;
86
90
let offset = constrainedColumnResize (
@@ -90,9 +94,9 @@ export function MTableHeader({ onColumnResized, ...props }) {
90
94
) ;
91
95
offset = Math . round ( offset ) ;
92
96
const widths = [ resizing . lastColData . width + alreadyOffset ] ;
93
- if ( props . tableWidth === 'full' ) {
97
+ if ( props . tableWidth === 'full' && resizing . lastNextColData ) {
94
98
offset = - constrainedColumnResize (
95
- props . columns [ resizing . nextColIndex ] ,
99
+ displayingColumns [ resizing . nextColIndex ] ,
96
100
resizing . lastNextColData . width - alreadyOffset ,
97
101
- offset
98
102
) ;
@@ -116,7 +120,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
116
120
( e ) => {
117
121
if ( resizing && lastX !== resizing . startX ) {
118
122
onColumnResized (
119
- props . columns [ resizing . colIndex ] . tableData . id ,
123
+ displayingColumns [ resizing . colIndex ] . tableData . id ,
120
124
0 ,
121
125
[ ] ,
122
126
[ ]
@@ -193,11 +197,8 @@ export function MTableHeader({ onColumnResized, ...props }) {
193
197
function RenderHeader ( ) {
194
198
const size = props . options . padding === 'default' ? 'medium' : 'small' ;
195
199
196
- return props . columns
197
- . filter (
198
- ( columnDef ) =>
199
- ! columnDef . hidden && ! ( columnDef . tableData . groupOrder > - 1 )
200
- )
200
+ return displayingColumns
201
+ . filter ( ( columnDef ) => ! ( columnDef . tableData . groupOrder > - 1 ) )
201
202
. sort ( ( a , b ) => a . tableData . columnOrder - b . tableData . columnOrder )
202
203
. map ( ( columnDef , index , allCols ) => {
203
204
let content = columnDef . title ;
@@ -396,7 +397,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
396
397
/>
397
398
) ;
398
399
}
399
- props . columns
400
+ displayingColumns
400
401
. filter ( ( columnDef ) => columnDef . tableData . groupOrder > - 1 )
401
402
. forEach ( ( columnDef ) => {
402
403
headers . splice (
0 commit comments