Skip to content

Commit 0789e78

Browse files
committed
fix conflict
2 parents a0a173c + 1c31aab commit 0789e78

File tree

9 files changed

+118
-13
lines changed

9 files changed

+118
-13
lines changed

css/react-bootstrap-table.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@
230230
animation-duration: .3s;
231231
}
232232

233+
td.react-bs-table-expand-cell {
234+
cursor: pointer;
235+
}
236+
233237
@keyframes shake {
234238
from, to {
235239
transform: translate3d(0, 0, 0);

examples/js/expandRow/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Demo extends React.Component {
2828
{ renderLinks('expandRow/expand-row-by-column.js') }
2929
<ManageExpandExternal/>
3030
</Panel>
31-
<Panel header={ 'Expand Row with Selection' }>
31+
<Panel header={ 'Expand Row with Selection - Keep select column first' }>
3232
<span>You can enable/disable the expanding if you click row to select,
3333
configure <code>clickToExpand</code> in <code>selectRow</code> props, default is false</span>
3434
{ renderLinks('expandRow/expand-row-with-selection.js') }

examples/js/expandRow/expand-row-by-column.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default class ExpandRow extends React.Component {
7878
options={ options }
7979
expandableRow={ this.isExpandableRow }
8080
expandComponent={ this.expandComponent }
81+
expandColumnOptions={ { expandColumnVisible: true } }
8182
search>
8283
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
8384
<TableHeaderColumn dataField='name' expandable={ false }>Product Name</TableHeaderColumn>

examples/js/expandRow/expand-row-with-selection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default class ExpandRow extends React.Component {
8282
options={ options }
8383
expandableRow={ this.isExpandableRow }
8484
expandComponent={ this.expandComponent }
85+
expandColumnOptions={ { expandColumnVisible: true, expandColumnBeforeSelectColumn: false } }
8586
selectRow={ selectRow }>
8687
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
8788
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>

examples/js/expandRow/expandRow.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ export default class ExpandRow extends React.Component {
6868
);
6969
}
7070

71+
expandColumnComponent({ isExpandableRow, isExpanded }) {
72+
let content = '';
73+
74+
if (isExpandableRow) {
75+
content = (isExpanded ? '(-)' : '(+)' );
76+
} else {
77+
content = ' ';
78+
}
79+
return (
80+
<div> { content } </div>
81+
);
82+
}
83+
7184
render() {
7285
const options = {
7386
expandRowBgColor: 'rgb(242, 255, 163)'
@@ -77,6 +90,7 @@ export default class ExpandRow extends React.Component {
7790
options={ options }
7891
expandableRow={ this.isExpandableRow }
7992
expandComponent={ this.expandComponent }
93+
expandColumnOptions={ { expandColumnVisible: true, expandColumnComponent: this.expandColumnComponent } }
8094
search>
8195
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
8296
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>

src/BootstrapTable.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ class BootstrapTable extends Component {
328328
const toolBar = this.renderToolBar();
329329
const tableFilter = this.renderTableFilter(columns);
330330
const isSelectAll = this.isSelectAll();
331-
const colGroups = Util.renderColGroup(columns, this.props.selectRow);
331+
const expandColumnOptions = this.props.expandColumnOptions;
332+
if (typeof expandColumnOptions.expandColumnBeforeSelectColumn === 'undefined') {
333+
expandColumnOptions.expandColumnBeforeSelectColumn = true;
334+
}
335+
const colGroups = Util.renderColGroup(columns, this.props.selectRow, expandColumnOptions);
332336
let sortIndicator = this.props.options.sortIndicator;
333337
if (typeof this.props.options.sortIndicator === 'undefined') sortIndicator = true;
334338
const { paginationPosition = Const.PAGINATION_POS_BOTTOM } = this.props.options;
@@ -362,7 +366,10 @@ class BootstrapTable extends Component {
362366
condensed={ this.props.condensed }
363367
isFiltered={ this.filter ? true : false }
364368
isSelectAll={ isSelectAll }
365-
reset={ this.state.reset }>
369+
reset={ this.state.reset }
370+
expandColumnVisible={ expandColumnOptions.expandColumnVisible }
371+
expandColumnComponent={ expandColumnOptions.expandColumnComponent }
372+
expandColumnBeforeSelectColumn={ expandColumnOptions.expandColumnBeforeSelectColumn }>
366373
{ this.props.children }
367374
</TableHeader>
368375
<TableBody ref='body'
@@ -382,6 +389,7 @@ class BootstrapTable extends Component {
382389
keyField={ this.store.getKeyField() }
383390
condensed={ this.props.condensed }
384391
selectRow={ this.props.selectRow }
392+
expandColumnOptions={ this.props.expandColumnOptions }
385393
cellEdit={ this.props.cellEdit }
386394
selectedRowKeys={ this.state.selectedRowKeys }
387395
onRowClick={ this.handleRowClick }
@@ -1365,12 +1373,22 @@ BootstrapTable.propTypes = {
13651373
csvFileName: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
13661374
ignoreSinglePage: PropTypes.bool,
13671375
expandableRow: PropTypes.func,
1368-
expandComponent: PropTypes.func
1376+
expandComponent: PropTypes.func,
1377+
expandColumnOptions: PropTypes.shape({
1378+
expandColumnVisible: PropTypes.bool,
1379+
expandColumnComponent: PropTypes.func,
1380+
expandColumnBeforeSelectColumn: PropTypes.bool
1381+
})
13691382
};
13701383
BootstrapTable.defaultProps = {
13711384
scrollTop: undefined,
13721385
expandComponent: undefined,
13731386
expandableRow: undefined,
1387+
expandColumnOptions: {
1388+
expandColumnVisible: false,
1389+
expandColumnComponent: undefined,
1390+
expandColumnBeforeSelectColumn: true
1391+
},
13741392
height: '100%',
13751393
maxHeight: undefined,
13761394
striped: false,

src/TableBody.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

src/TableHeader.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ class TableHeader extends Component {
5151
const rows = [];
5252
let rowKey = 0;
5353

54-
if (!this.props.hideSelectColumn) {
55-
rows[0] = [ this.renderSelectRowHeader(rowCount + 1, rowKey++) ];
56-
}
57-
54+
rows[0] = [];
55+
rows[0].push( [
56+
this.props.expandColumnVisible &&
57+
this.props.expandColumnBeforeSelectColumn &&
58+
<th className='react-bs-table-expand-cell'> </th>
59+
], [
60+
this.renderSelectRowHeader(rowCount + 1, rowKey++)
61+
], [
62+
this.props.expandColumnVisible &&
63+
!this.props.expandColumnBeforeSelectColumn &&
64+
<th className='react-bs-table-expand-cell'> </th>
65+
]);
5866
const { sortIndicator, sortList, onSort, reset } = this.props;
5967

6068
React.Children.forEach(this.props.children, (elm) => {
@@ -141,7 +149,10 @@ TableHeader.propTypes = {
141149
sortIndicator: PropTypes.bool,
142150
customComponent: PropTypes.func,
143151
colGroups: PropTypes.element,
144-
reset: PropTypes.bool
152+
reset: PropTypes.bool,
153+
expandColumnVisible: PropTypes.bool,
154+
expandColumnComponent: PropTypes.func,
155+
expandColumnBeforeSelectColumn: PropTypes.bool
145156
};
146157

147158
export default TableHeader;

src/util.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export default {
4646
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
4747
},
4848

49-
renderColGroup(columns, selectRow) {
49+
renderColGroup(columns, selectRow, expandColumnOptions = {}) {
5050
let selectRowHeader = null;
51+
let expandRowHeader = null;
5152
const isSelectRowDefined = selectRow.mode === Const.ROW_SELECT_SINGLE ||
5253
selectRow.mode === Const.ROW_SELECT_MULTI;
5354
if (isSelectRowDefined) {
@@ -56,9 +57,16 @@ export default {
5657
minWidth: selectRow.columnWidth || '30px'
5758
};
5859
if (!selectRow.hideSelectColumn) {
59-
selectRowHeader = (<col style={ style } key={ -1 }></col>);
60+
selectRowHeader = (<col key='select-col' style={ style }></col>);
6061
}
6162
}
63+
if (expandColumnOptions.expandColumnVisible) {
64+
const style = {
65+
width: expandColumnOptions.columnWidth || 30,
66+
minWidth: expandColumnOptions.columnWidth || 30
67+
};
68+
expandRowHeader = (<col key='expand-col' style={ style }></col>);
69+
}
6270
const theader = columns.map(function(column, i) {
6371
const style = {
6472
display: column.hidden ? 'none' : null
@@ -75,7 +83,14 @@ export default {
7583

7684
return (
7785
<colgroup>
78-
{ selectRowHeader }{ theader }
86+
{ expandColumnOptions.expandColumnVisible &&
87+
expandColumnOptions.expandColumnBeforeSelectColumn &&
88+
expandRowHeader }
89+
{ selectRowHeader }
90+
{ expandColumnOptions.expandColumnVisible &&
91+
!expandColumnOptions.expandColumnBeforeSelectColumn &&
92+
expandRowHeader }
93+
{ theader }
7994
</colgroup>
8095
);
8196
}

0 commit comments

Comments
 (0)