@@ -22,6 +22,13 @@ export default function expanded(BaseComponent, stickyLock) {
22
22
* @returns {Element }
23
23
*/
24
24
expandedRowRender : PropTypes . func ,
25
+ /**
26
+ * 设置行是否可展开,设置 false 为不可展开
27
+ * @param {Object } record 该行所对应的数据
28
+ * @param {Number } index 该行所对应的序列
29
+ * @returns {Boolean } 是否可展开
30
+ */
31
+ rowExpandable : PropTypes . func ,
25
32
/**
26
33
* 额外渲染行的缩进
27
34
*/
@@ -64,6 +71,7 @@ export default function expanded(BaseComponent, stickyLock) {
64
71
static childContextTypes = {
65
72
openRowKeys : PropTypes . array ,
66
73
expandedRowRender : PropTypes . func ,
74
+ rowExpandable : PropTypes . func ,
67
75
expandedIndexSimulate : PropTypes . bool ,
68
76
expandedRowWidthEquals2Table : PropTypes . bool ,
69
77
expandedRowIndent : PropTypes . array ,
@@ -79,9 +87,7 @@ export default function expanded(BaseComponent, stickyLock) {
79
87
expandedRowRender : this . props . expandedRowRender ,
80
88
expandedIndexSimulate : this . props . expandedIndexSimulate ,
81
89
expandedRowWidthEquals2Table : stickyLock ,
82
- expandedRowIndent : stickyLock
83
- ? [ 0 , 0 ]
84
- : this . props . expandedRowIndent ,
90
+ expandedRowIndent : stickyLock ? [ 0 , 0 ] : this . props . expandedRowIndent ,
85
91
} ;
86
92
}
87
93
@@ -105,23 +111,19 @@ export default function expanded(BaseComponent, stickyLock) {
105
111
} ;
106
112
107
113
renderExpandedCell = ( value , index , record ) => {
108
- const { getExpandedColProps, prefix, locale } = this . props ;
114
+ const { getExpandedColProps, prefix, locale, rowExpandable } = this . props ;
115
+
116
+ if ( typeof rowExpandable === 'function' && ! rowExpandable ( record , index ) ) {
117
+ return '' ;
118
+ }
109
119
110
120
const { openRowKeys } = this . state ,
111
121
{ primaryKey } = this . props ,
112
122
hasExpanded = openRowKeys . indexOf ( record [ primaryKey ] ) > - 1 ,
113
123
switchNode = hasExpanded ? (
114
- < Icon
115
- type = "minus"
116
- size = "xs"
117
- className = { `${ prefix } table-expand-unfold` }
118
- />
124
+ < Icon type = "minus" size = "xs" className = { `${ prefix } table-expand-unfold` } />
119
125
) : (
120
- < Icon
121
- type = "add"
122
- size = "xs"
123
- className = { `${ prefix } table-expand-fold` }
124
- />
126
+ < Icon type = "add" size = "xs" className = { `${ prefix } table-expand-fold` } />
125
127
) ,
126
128
attrs = getExpandedColProps ( record , index ) || { } ;
127
129
const cls = classnames ( {
@@ -131,24 +133,14 @@ export default function expanded(BaseComponent, stickyLock) {
131
133
} ) ;
132
134
133
135
if ( ! attrs . disabled ) {
134
- attrs . onClick = this . onExpandedClick . bind (
135
- this ,
136
- value ,
137
- record ,
138
- index
139
- ) ;
136
+ attrs . onClick = this . onExpandedClick . bind ( this , value , record , index ) ;
140
137
}
141
138
return (
142
139
< span
143
140
{ ...attrs }
144
141
role = "button"
145
142
tabIndex = "0"
146
- onKeyDown = { this . expandedKeydown . bind (
147
- this ,
148
- value ,
149
- record ,
150
- index
151
- ) }
143
+ onKeyDown = { this . expandedKeydown . bind ( this , value , record , index ) }
152
144
aria-label = { hasExpanded ? locale . expanded : locale . folded }
153
145
aria-expanded = { hasExpanded }
154
146
className = { cls }
@@ -228,6 +220,7 @@ export default function expanded(BaseComponent, stickyLock) {
228
220
components,
229
221
openRowKeys,
230
222
expandedRowRender,
223
+ rowExpandable,
231
224
hasExpandedRowCtrl,
232
225
children,
233
226
columns,
0 commit comments