Your search did not match any results.
Scroll View

Scroll View

Documentation

The ScrollView is a widget that enables a user to scroll its content. This demo shows how to display the scrollbar within a container and how to update the ScrollView content.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import service from './data.js'; import ScrollView from 'devextreme-react/scroll-view'; import SelectBox from 'devextreme-react/select-box'; import CheckBox from 'devextreme-react/check-box'; class App extends React.Component { constructor(props) { super(props); this.state = { showScrollBarMode: 'onScroll', pullDown: false, scrollByContent: true, scrollByThumb: true, content: service.getContent() }; this.getInstance = this.getInstance.bind(this); this.pullDownValueChanged = this.pullDownValueChanged.bind(this); this.reachBottomValueChanged = this.reachBottomValueChanged.bind(this); this.scrollbarModelValueChanged = this.scrollbarModelValueChanged.bind(this); this.scrollByContentValueChanged = this.scrollByContentValueChanged.bind(this); this.scrollByThumbValueChanged = this.scrollByThumbValueChanged.bind(this); this.updateTopContent = this.updateTopContent.bind(this); this.updateBottomContent = this.updateBottomContent.bind(this); this.updateContent = this.updateContent.bind(this); } render() { let { showScrollBarMode, content, scrollByThumb, scrollByContent, pullDown } = this.state; return ( <div id={'scrollview-demo'}> <ScrollView id={'scrollview'} ref={this.getInstance} reachBottomText={'Updating...'} scrollByContent={scrollByContent} bounceEnabled={pullDown} onReachBottom={this.updateBottomContent} onPullDown={this.updateTopContent} showScrollbar={showScrollBarMode} scrollByThumb={scrollByThumb}> <div className={'text-content'}> {content} </div> </ScrollView> <div className={'options'}> <div className={'caption'}>Options</div> <div className={'option'}> <span>Show scrollbar: </span> <SelectBox items={showScrollbarModes} valueExpr={'value'} displayExpr={'text'} value={showScrollBarMode} onValueChanged={this.scrollbarModelValueChanged} /> </div> <div className={'option'}> <CheckBox text={'Update content on the ReachBottom event'} defaultValue={true} onValueChanged={this.reachBottomValueChanged} /> </div> <div className={'option'}> <CheckBox text={'Update content on the PullDown event'} value={pullDown} onValueChanged={this.pullDownValueChanged} /> </div> <div className={'option'}> <CheckBox text={'Scroll by content'} value={scrollByContent} onValueChanged={this.scrollByContentValueChanged} /> </div> <div className={'option'}> <CheckBox text={'Scroll by thumb'} value={scrollByThumb} onValueChanged={this.scrollByThumbValueChanged} /> </div> </div> </div> ); } getInstance(ref) { this.scrollView = ref.instance; } pullDownValueChanged(args) { this.setState({ pullDown: args.value }); } reachBottomValueChanged(args) { this.scrollView.option('onReachBottom', args.value ? this.updateBottomContent : null); } scrollbarModelValueChanged(args) { this.setState({ showScrollBarMode: args.value }); } scrollByContentValueChanged(args) { this.setState({ scrollByContent: args.value }); } scrollByThumbValueChanged(args) { this.setState({ scrollByThumb: args.value }); } updateTopContent(args) { this.updateContent(args, 'PullDown'); } updateBottomContent(args) { this.updateContent(args, 'ReachBottom'); } updateContent(args, eventName) { let updateContentText = `\n Content has been updated on the ${ eventName } event.\n\n`; if (this.updateContentTimer) { clearTimeout(this.updateContentTimer); } this.updateContentTimer = setTimeout(() => { this.setState({ content: eventName == 'PullDown' ? updateContentText + this.state.content : this.state.content + updateContentText }); args.component.release(); }, 500); } } const showScrollbarModes = [{ text: 'On Scroll', value: 'onScroll' }, { text: 'On Hover', value: 'onHover' }, { text: 'Always', value: 'always' }, { text: 'Never', value: 'never' }]; export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.light.css" /> <link rel="stylesheet" type ="text/css" href="styles.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
#scrollview-demo { min-height: 550px; } .text-content { white-space: pre-wrap; } #scrollview { height: auto; position: absolute; top: 0; bottom: 300px; padding: 20px; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); position: absolute; bottom: 0; left: 0; right: 0; } .caption { font-size: 18px; font-weight: 500; } .option { margin-top: 10px; } .option > span { position: relative; top: 2px; margin-right: 10px; } .option > .dx-selectbox { display: inline-block; vertical-align: middle; max-width: 340px; width: 100%; }
let longText = ''; for (var i = 0; i < 10; i++) { longText += 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n'; } export default { getContent() { return longText; } };
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16/umd/react.development.js', 'react-dom': 'npm:react-dom@16/umd/react-dom.development.js', 'prop-types': 'npm:prop-types/prop-types.js', 'devextreme': 'npm:devextreme@19.1', 'devextreme-react': 'npm:devextreme-react@19.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.6/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });