【发布时间】:2018-01-06 16:56:14
【问题描述】:
我已经在 react-virtualized 的网格上实现了,用户可以通过单击图标对值进行排序。我希望该图标与react-bootstrap table 上的排序图标具有相同的行为。
目前,我的图标正在使用 this。当我单击列字符串时,列号不会回到圆形图标。
这是我的排序组件:
class SortColumn extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
this.state = {
sortIcon: 'fa fa-circle',
id: null,
};
}
onClick() {
const { columnId, sort } = this.props;
const newSort = sort;
newSort.id = columnId;
if (sort.asc === true) {
newSort.asc = false;
this.setState({
sortIcon: 'fa fa-chevron-down',
id: columnId,
});
} else if (sort.asc === false) {
newSort.asc = true;
this.setState({
sortIcon: 'fa fa-chevron-up',
id: columnId,
});
}
this.props.updateSort(newSort);
}
render() {
return (
<i
onClick={this.onClick}
styleName="columnSettingsSort"
className={this.state.sortIcon} aria-hidden="true"
/>
);
}
}
你有什么想法吗?
【问题讨论】:
标签: javascript reactjs sorting react-virtualized