1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { log } from '../../util' ;
3
+ import { log , dom , events } from '../../util' ;
4
4
import Row from '../lock/row' ;
5
5
6
6
export default class ExpandedRow extends React . Component {
@@ -21,6 +21,34 @@ export default class ExpandedRow extends React.Component {
21
21
lockType : PropTypes . oneOf ( [ 'left' , 'right' ] ) ,
22
22
} ;
23
23
24
+ componentDidMount ( ) {
25
+ events . on ( window , 'resize' , this . setExpandedWidth ) ;
26
+ }
27
+
28
+ componentDidUpdate ( ) {
29
+ this . setExpandedWidth ( ) ;
30
+ }
31
+
32
+ componentWillUnmount ( ) {
33
+ events . off ( window , 'resize' , this . setExpandedWidth ) ;
34
+ }
35
+
36
+ getExpandedRow = ( parentKey , ref ) => {
37
+ if ( ! this . expandedRowRef ) {
38
+ this . expandedRowRef = { } ;
39
+ }
40
+ this . expandedRowRef [ parentKey ] = ref ;
41
+ } ;
42
+
43
+ setExpandedWidth = ( ) => {
44
+ const { tableEl } = this . props ;
45
+ const totalWidth = + ( tableEl && tableEl . clientWidth ) - 2 || '100%' ;
46
+
47
+ Object . keys ( this . expandedRowRef || { } ) . forEach ( key => {
48
+ dom . setStyle ( this . expandedRowRef [ key ] , { width : totalWidth } ) ;
49
+ } ) ;
50
+ } ;
51
+
24
52
renderExpandedRow ( record , rowIndex ) {
25
53
const {
26
54
expandedRowRender,
@@ -30,7 +58,6 @@ export default class ExpandedRow extends React.Component {
30
58
expandedIndexSimulate,
31
59
expandedRowWidthEquals2Table,
32
60
} = this . context ;
33
- const { tableOuterWidth } = this . props ;
34
61
const expandedIndex = expandedIndexSimulate ? ( rowIndex - 1 ) / 2 : rowIndex ;
35
62
36
63
const { columns, cellRef } = this . props ;
@@ -76,7 +103,6 @@ export default class ExpandedRow extends React.Component {
76
103
77
104
const expandedRowStyle = {
78
105
position : 'sticky' ,
79
- width : ( tableOuterWidth || 0 ) - 1 ,
80
106
left : 0 ,
81
107
} ;
82
108
// 暴露给用户的index
@@ -85,14 +111,19 @@ export default class ExpandedRow extends React.Component {
85
111
content = (
86
112
< div
87
113
className = { `${ prefix } table-cell-wrapper` }
114
+ ref = { this . getExpandedRow . bind ( this , record [ primaryKey ] ) }
88
115
style = { expandedRowWidthEquals2Table && expandedRowStyle }
89
116
>
90
117
{ content }
91
118
</ div >
92
119
) ;
93
120
} else {
94
121
content = expandedRowWidthEquals2Table ? (
95
- < div className = { `${ prefix } table-expanded-area` } style = { expandedRowStyle } >
122
+ < div
123
+ className = { `${ prefix } table-expanded-area` }
124
+ ref = { this . getExpandedRow . bind ( this , record [ primaryKey ] ) }
125
+ style = { expandedRowStyle }
126
+ >
96
127
{ content }
97
128
</ div >
98
129
) : (
0 commit comments