From 20a0d657624b88f7105482a1d0d3ca7e7d715ec2 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Tue, 13 Dec 2016 23:41:49 +0800 Subject: [PATCH] fix #860 --- src/BootstrapTable.js | 15 +++++++++++++++ src/Const.js | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index b24fe37b5..6a27eb172 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -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() { @@ -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; } @@ -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, @@ -1114,6 +1128,7 @@ BootstrapTable.propTypes = { expandComponent: PropTypes.func }; BootstrapTable.defaultProps = { + scrollTop: undefined, expandComponent: undefined, expandableRow: undefined, height: '100%', diff --git a/src/Const.js b/src/Const.js index 04fbc842c..f77ce5f91 100644 --- a/src/Const.js +++ b/src/Const.js @@ -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',