@@ -31,7 +31,8 @@ class TableBody extends Component {
3131 const noneditableRows = ( cellEdit . nonEditableRows && cellEdit . nonEditableRows ( ) ) || [ ] ;
3232 const unselectable = this . props . selectRow . unselectable || [ ] ;
3333 const isSelectRowDefined = this . _isSelectRowDefined ( ) ;
34- const tableHeader = Utils . renderColGroup ( this . props . columns , this . props . selectRow , 'header' ) ;
34+ const tableHeader = Utils . renderColGroup ( this . props . columns ,
35+ this . props . selectRow , this . props . expandColumnOptions ) ;
3536 const inputType = this . props . selectRow . mode === Const . ROW_SELECT_SINGLE ? 'radio' : 'checkbox' ;
3637 const CustomComponent = this . props . selectRow . customComponent ;
3738 const enableKeyBoardNav = ( keyBoardNav === true || typeof keyBoardNav === 'object' ) ;
@@ -41,11 +42,16 @@ class TableBody extends Component {
4142 const customNavStyle = typeof keyBoardNav === 'object' ?
4243 keyBoardNav . customStyle :
4344 null ;
45+ const ExpandColumnCustomComponent = this . props . expandColumnOptions . expandColumnComponent ;
4446 let expandColSpan = this . props . columns . filter ( col => ! col . hidden ) . length ;
4547 if ( isSelectRowDefined && ! this . props . selectRow . hideSelectColumn ) {
4648 expandColSpan += 1 ;
4749 }
4850 let tabIndex = 1 ;
51+ if ( this . props . expandColumnOptions . expandColumnVisible ) {
52+ expandColSpan += 1 ;
53+ }
54+
4955 const tableRows = this . props . data . map ( function ( data , r ) {
5056 const tableColumns = this . props . columns . map ( function ( column , i ) {
5157 const fieldValue = data [ column . name ] ;
@@ -135,6 +141,11 @@ class TableBody extends Component {
135141 const selected = this . props . selectedRowKeys . indexOf ( key ) !== - 1 ;
136142 const selectRowColumn = isSelectRowDefined && ! this . props . selectRow . hideSelectColumn ?
137143 this . renderSelectRowColumn ( selected , inputType , disable , CustomComponent , r , data ) : null ;
144+ const expandedRowColumn = this . renderExpandRowColumn (
145+ this . props . expandableRow && this . props . expandableRow ( data ) ,
146+ this . props . expanding . indexOf ( key ) > - 1 ,
147+ ExpandColumnCustomComponent , r , data
148+ ) ;
138149 // add by bluespring for className customize
139150 let trClassName = this . props . trClassName ;
140151 if ( isFun ( this . props . trClassName ) ) {
@@ -151,7 +162,13 @@ class TableBody extends Component {
151162 onSelectRow = { this . handleSelectRow }
152163 onExpandRow = { this . handleClickCell }
153164 unselectableRow = { disable } >
165+ { this . props . expandColumnOptions . expandColumnVisible &&
166+ this . props . expandColumnOptions . expandColumnBeforeSelectColumn &&
167+ expandedRowColumn }
154168 { selectRowColumn }
169+ { this . props . expandColumnOptions . expandColumnVisible &&
170+ ! this . props . expandColumnOptions . expandColumnBeforeSelectColumn &&
171+ expandedRowColumn }
155172 { tableColumns }
156173 </ TableRow > ] ;
157174
@@ -283,6 +300,7 @@ class TableBody extends Component {
283300 } = this . props ;
284301 const selectRowAndExpand = this . _isSelectRowDefined ( ) && ! clickToExpand ? false : true ;
285302 columnIndex = this . _isSelectRowDefined ( ) ? columnIndex - 1 : columnIndex ;
303+ columnIndex = this . _isExpandColumnVisible ( ) ? columnIndex - 1 : columnIndex ;
286304 if ( expandableRow &&
287305 selectRowAndExpand &&
288306 ( expandBy === Const . EXPAND_BY_ROW ||
@@ -371,11 +389,34 @@ class TableBody extends Component {
371389 ) ;
372390 }
373391
392+ renderExpandRowColumn ( isExpandableRow , isExpanded , CustomComponent , rowIndex = null ) {
393+ let content = null ;
394+ if ( CustomComponent ) {
395+ content = ( < CustomComponent isExpandableRow = { isExpandableRow } isExpanded = { isExpanded } /> ) ;
396+ } else if ( isExpandableRow ) {
397+ content = ( isExpanded ? '-' : '+' ) ;
398+ } else {
399+ content = ' ' ;
400+ }
401+
402+ return (
403+ < td
404+ className = 'react-bs-table-expand-cell'
405+ onClick = { ( ) => this . handleClickCell ( rowIndex + 1 ) } >
406+ { content }
407+ </ td >
408+ ) ;
409+ }
410+
374411 _isSelectRowDefined ( ) {
375412 return this . props . selectRow . mode === Const . ROW_SELECT_SINGLE ||
376413 this . props . selectRow . mode === Const . ROW_SELECT_MULTI ;
377414 }
378415
416+ _isExpandColumnVisible ( ) {
417+ return this . props . expandColumnOptions . expandColumnVisible ;
418+ }
419+
379420 getHeaderColGrouop = ( ) => {
380421 return this . refs . header . childNodes ;
381422 }
0 commit comments