Skip to content

Commit

Permalink
fix #860
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Dec 13, 2016
1 parent e194fc4 commit 20a0d65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class BootstrapTable extends Component {
this._adjustTable();
window.addEventListener('resize', this._adjustTable);
this.refs.body.refs.container.addEventListener('scroll', this._scrollHeader);
if (this.props.scrollTop) {
this._scrollTop();
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -904,6 +907,16 @@ class BootstrapTable extends Component {
}
}

_scrollTop = () => {
const { scrollTop } = this.props;
if (scrollTop === Const.SCROLL_TOP) {
this.refs.body.refs.container.scrollTop = 0;
} else if (scrollTop === Const.SCROLL_BOTTOM) {
this.refs.body.refs.container.scrollTop = this.refs.body.refs.container.scrollHeight;
} else if (typeof scrollTop === 'number' && !isNaN(scrollTop)) {
this.refs.body.refs.container.scrollTop = scrollTop;
}
}
_scrollHeader = (e) => {
this.refs.header.refs.container.scrollLeft = e.currentTarget.scrollLeft;
}
Expand Down Expand Up @@ -1013,6 +1026,7 @@ BootstrapTable.propTypes = {
maxHeight: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
data: PropTypes.oneOfType([ PropTypes.array, PropTypes.object ]),
remote: PropTypes.bool, // remote data, default is false
scrollTop: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
striped: PropTypes.bool,
bordered: PropTypes.bool,
hover: PropTypes.bool,
Expand Down Expand Up @@ -1114,6 +1128,7 @@ BootstrapTable.propTypes = {
expandComponent: PropTypes.func
};
BootstrapTable.defaultProps = {
scrollTop: undefined,
expandComponent: undefined,
expandableRow: undefined,
height: '100%',
Expand Down
2 changes: 2 additions & 0 deletions src/Const.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default {
SAVE_BTN_TEXT: 'Save',
CLOSE_BTN_TEXT: 'Close',
FILTER_DELAY: 500,
SCROLL_TOP: 'Top',
SCROLL_BOTTOM: 'Bottom',
FILTER_TYPE: {
TEXT: 'TextFilter',
REGEX: 'RegexFilter',
Expand Down

0 comments on commit 20a0d65

Please sign in to comment.