Skip to content

Commit

Permalink
fix #424
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Apr 28, 2016
1 parent 686227f commit 3a95495
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ class TableHeader extends Component {
});
let selectRowHeaderCol = null;
if (!this.props.hideSelectColumn) selectRowHeaderCol = this.renderSelectRowHeader();
this._attachClearSortCaretFunc();

let i = 0;
return (
<div ref='container' className={ containerClasses } style={ this.props.style }>
<table className={ tableClasses }>
<thead>
<tr ref='header'>
{ selectRowHeaderCol }
{ this.props.children }
{
React.Children.map(this.props.children, (elm) => {
const { sortIndicator, sortName, sortOrder, onSort } = this.props;
const { dataField, dataSort } = elm.props;
const sort = (dataSort && dataField === sortName) ? sortOrder : undefined;
return React.cloneElement(elm, { key: i++, onSort, sort, sortIndicator });
})
}
</tr>
</thead>
</table>
Expand All @@ -61,25 +67,6 @@ class TableHeader extends Component {
return null;
}
}

_attachClearSortCaretFunc() {
const { sortIndicator, children, sortName, sortOrder, onSort } = this.props;
if (Array.isArray(children)) {
for (let i = 0; i < children.length; i++) {
const { dataField, dataSort } = children[i].props;
const sort = (dataSort && dataField === sortName) ? sortOrder : undefined;
this.props.children[i] =
React.cloneElement(children[i],
{ key: i, onSort, sort, sortIndicator });
}
} else {
const { dataField, dataSort } = children.props;
const sort = (dataSort && dataField === sortName) ? sortOrder : undefined;
this.props.children =
React.cloneElement(children,
{ key: 0, onSort, sort, sortIndicator });
}
}
}
TableHeader.propTypes = {
style: PropTypes.object,
Expand Down

0 comments on commit 3a95495

Please sign in to comment.