Skip to content

Commit 11e9daa

Browse files
author
Pin Lin
committed
add key props in select of header
1 parent 3dca40a commit 11e9daa

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/TableHeader.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ class TableHeader extends Component {
3131
'table-bordered': this.props.bordered,
3232
'table-condensed': this.props.condensed
3333
}, this.props.tableHeaderClass);
34-
let i = 0;
3534

36-
let rowCount = 0;
37-
React.Children.forEach(this.props.children, (elm) => {
38-
if (Number(elm.props.row) > rowCount) {
39-
rowCount = Number(elm.props.row);
40-
}
41-
});
35+
const rowCount = Math.max(React.Children.map(this.props.children, elm =>
36+
Number(elm.props.row)));
4237

4338
const rows = [];
39+
let rowKey = 0;
4440

4541
if (!this.props.hideSelectColumn) {
46-
rows[0] = [ this.renderSelectRowHeader(rowCount + 1) ];
42+
rows[0] = [ this.renderSelectRowHeader(rowCount + 1, rowKey++) ];
4743
}
4844

4945
React.Children.forEach(this.props.children, (elm) => {
@@ -57,11 +53,11 @@ class TableHeader extends Component {
5753
}
5854
if ((rowSpan + rowIndex) === (rowCount + 1)) {
5955
rows[rowIndex].push(React.cloneElement(
60-
elm, { key: i++, onSort, sort, sortIndicator, isOnlyHead: false }
56+
elm, { key: rowKey++, onSort, sort, sortIndicator, isOnlyHead: false }
6157
));
6258
} else {
6359
rows[rowIndex].push(React.cloneElement(
64-
elm, { key: i++, isOnlyHead: true }
60+
elm, { key: rowKey++, isOnlyHead: true }
6561
));
6662
}
6763
});
@@ -90,21 +86,21 @@ class TableHeader extends Component {
9086
return this.refs.headerGrp.childNodes;
9187
}
9288

93-
renderSelectRowHeader(rowCount) {
89+
renderSelectRowHeader(rowCount, rowKey) {
9490
if (this.props.customComponent) {
9591
const CustomComponent = this.props.customComponent;
9692
return (
97-
<SelectRowHeaderColumn rowCount={ rowCount }>
93+
<SelectRowHeaderColumn key={ rowKey } rowCount={ rowCount }>
9894
<CustomComponent type='checkbox' checked={ this.props.isSelectAll }
9995
indeterminate={ this.props.isSelectAll === 'indeterminate' } disabled={ false }
10096
onChange={ this.props.onSelectAllRow } rowIndex='Header'/>
10197
</SelectRowHeaderColumn>
10298
);
10399
} else if (this.props.rowSelectType === Const.ROW_SELECT_SINGLE) {
104-
return (<SelectRowHeaderColumn rowCount={ rowCount }/>);
100+
return (<SelectRowHeaderColumn key={ rowKey } rowCount={ rowCount }/>);
105101
} else if (this.props.rowSelectType === Const.ROW_SELECT_MULTI) {
106102
return (
107-
<SelectRowHeaderColumn rowCount={ rowCount }>
103+
<SelectRowHeaderColumn key={ rowKey } rowCount={ rowCount }>
108104
<Checkbox
109105
onChange={ this.props.onSelectAllRow }
110106
checked={ this.props.isSelectAll }/>

0 commit comments

Comments
 (0)