Skip to content

Commit 20a0d65

Browse files
committed
fix #860
1 parent e194fc4 commit 20a0d65

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/BootstrapTable.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ class BootstrapTable extends Component {
206206
this._adjustTable();
207207
window.addEventListener('resize', this._adjustTable);
208208
this.refs.body.refs.container.addEventListener('scroll', this._scrollHeader);
209+
if (this.props.scrollTop) {
210+
this._scrollTop();
211+
}
209212
}
210213

211214
componentWillUnmount() {
@@ -904,6 +907,16 @@ class BootstrapTable extends Component {
904907
}
905908
}
906909

910+
_scrollTop = () => {
911+
const { scrollTop } = this.props;
912+
if (scrollTop === Const.SCROLL_TOP) {
913+
this.refs.body.refs.container.scrollTop = 0;
914+
} else if (scrollTop === Const.SCROLL_BOTTOM) {
915+
this.refs.body.refs.container.scrollTop = this.refs.body.refs.container.scrollHeight;
916+
} else if (typeof scrollTop === 'number' && !isNaN(scrollTop)) {
917+
this.refs.body.refs.container.scrollTop = scrollTop;
918+
}
919+
}
907920
_scrollHeader = (e) => {
908921
this.refs.header.refs.container.scrollLeft = e.currentTarget.scrollLeft;
909922
}
@@ -1013,6 +1026,7 @@ BootstrapTable.propTypes = {
10131026
maxHeight: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
10141027
data: PropTypes.oneOfType([ PropTypes.array, PropTypes.object ]),
10151028
remote: PropTypes.bool, // remote data, default is false
1029+
scrollTop: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
10161030
striped: PropTypes.bool,
10171031
bordered: PropTypes.bool,
10181032
hover: PropTypes.bool,
@@ -1114,6 +1128,7 @@ BootstrapTable.propTypes = {
11141128
expandComponent: PropTypes.func
11151129
};
11161130
BootstrapTable.defaultProps = {
1131+
scrollTop: undefined,
11171132
expandComponent: undefined,
11181133
expandableRow: undefined,
11191134
height: '100%',

src/Const.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default {
2525
SAVE_BTN_TEXT: 'Save',
2626
CLOSE_BTN_TEXT: 'Close',
2727
FILTER_DELAY: 500,
28+
SCROLL_TOP: 'Top',
29+
SCROLL_BOTTOM: 'Bottom',
2830
FILTER_TYPE: {
2931
TEXT: 'TextFilter',
3032
REGEX: 'RegexFilter',

0 commit comments

Comments
 (0)