Your search did not match any results.
Accordion

Accordion

Documentation

The Accordion widget contains several panels displayed one under another. These panels can be collapsed or expanded by a user, which makes this widget very useful for presenting information in a limited amount of space.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import { Accordion, CheckBox, TagBox } from 'devextreme-react'; import Slider, { Tooltip, Label } from 'devextreme-react/slider'; import service from './data.js'; import CustomTitle from './CustomTitle.js'; import CustomItem from './CustomItem.js'; class App extends React.Component { constructor(props) { super(props); this.companies = service.getCompanies(); this.state = { selectedItems: [this.companies[0]], multiple: false, collapsible: false, animationDuration: 300 }; this.selectionChanged = this.selectionChanged.bind(this); this.selectedItemsChanged = this.selectedItemsChanged.bind(this); this.multipleChanged = this.multipleChanged.bind(this); this.collapsibleChanged = this.collapsibleChanged.bind(this); this.animationDurationChanged = this.animationDurationChanged.bind(this); } render() { const { selectedItems, multiple, collapsible, animationDuration } = this.state; return ( <div id={'accordion'}> <Accordion dataSource={this.companies} collapsible={collapsible} multiple={multiple} animationDuration={animationDuration} selectedItems={selectedItems} onSelectionChanged={this.selectionChanged} itemTitleComponent={CustomTitle} itemComponent={CustomItem} /> <div className={'selected-data'}> <span className={'caption'}>Selected Items</span> <TagBox dataSource={this.companies} displayExpr={'CompanyName'} value={selectedItems} onValueChanged={this.selectedItemsChanged} disabled={!multiple} /> </div> <div className={'options'}> <div className={'caption'}>Options</div> <div className={'option'}> <CheckBox text={'Multiple enabled'} value={multiple} onValueChanged={this.multipleChanged} /> </div> <div className={'option'}> <CheckBox text={'Collapsible enabled'} value={collapsible} onValueChanged={this.collapsibleChanged} /> </div> <div className={'option'}> <span>Animation duration</span> <Slider min={0} max={1000} value={animationDuration} onValueChanged={this.animationDurationChanged} > <Tooltip enabled={true} position={'bottom'} /> <Label visible={true} /> </Slider> </div> </div> </div> ); } selectionChanged(e) { let newItems = [...this.state.selectedItems]; e.removedItems.forEach(item => { let index = newItems.indexOf(item); if (index >= 0) { newItems.splice(index, 1); } }); if (e.addedItems.length) { newItems = [...newItems, ...e.addedItems]; } this.setState({ selectedItems: newItems }); } selectedItemsChanged(e) { this.setState({ selectedItems: e.value }); } multipleChanged(e) { this.setState({ multiple: e.value }); } collapsibleChanged(e) { this.setState({ collapsible: e.value }); } animationDurationChanged(e) { this.setState({ animationDuration: e.value }); } } export default App;
import React from 'react'; export default function CustomItem(data) { return ( <div> <div> <p> <b>{data.City} </b> (<span>{data.State}</span>) </p> <p> <span>{data.Zipcode} </span> <span>{data.Address}</span> </p> </div> <div> <p> Phone: <b>{data.Phone}</b> </p> <p> Fax: <b>{data.Fax}</b> </p> <p> Website: <a href={data.Website} target={'_blank'}> {data.Website} </a> </p> </div> </div> ); }
import React from 'react'; export default function CustomTitle(data) { return ( <h1>{data.CompanyName}</h1> ); }
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/18.2.7/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/18.2.7/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>
#accordion h1 { font-size: 20px; } #accordion h1, #accordion p { margin: 0; } .dx-theme-material #accordion .dx-accordion-item-opened h1 { margin-top: 7px; } .options, .selected-data { padding: 20px; background-color: rgba(191, 191, 191, 0.15); margin-top: 20px; } .selected-data { position: relative; height: 36px; } .selected-data > .caption { position: relative; top: 5px; margin-right: 10px; font-weight: bold; font-size: 115%; } .selected-data > .dx-widget { position: absolute; left: 140px; right: 20px; top: 20px; } .options > .caption { font-weight: 500; font-size: 18px; } .option { margin-top: 10px; }
const companies = [{ 'ID': 1, 'CompanyName': 'Super Mart of the West', 'Address': '702 SW 8th Street', 'City': 'Bentonville', 'State': 'Arkansas', 'Zipcode': 72716, 'Phone': '(800) 555-2797', 'Fax': '(800) 555-2171', 'Website': 'http://www.nowebsitesupermart.com' }, { 'ID': 2, 'CompanyName': 'Electronics Depot', 'Address': '2455 Paces Ferry Road NW', 'City': 'Atlanta', 'State': 'Georgia', 'Zipcode': 30339, 'Phone': '(800) 595-3232', 'Fax': '(800) 595-3231', 'Website': 'http://www.nowebsitedepot.com' }, { 'ID': 3, 'CompanyName': 'K&S Music', 'Address': '1000 Nicllet Mall', 'City': 'Minneapolis', 'State': 'Minnesota', 'Zipcode': 55403, 'Phone': '(612) 304-6073', 'Fax': '(612) 304-6074', 'Website': 'http://www.nowebsitemusic.com' }, { 'ID': 4, 'CompanyName': "Tom's Club", 'Address': '999 Lake Drive', 'City': 'Issaquah', 'State': 'Washington', 'Zipcode': 98027, 'Phone': '(800) 955-2292', 'Fax': '(800) 955-2293', 'Website': 'http://www.nowebsitetomsclub.com' }]; export default { getCompanies() { return companies; } };
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@18.2', 'devextreme-react': 'npm:devextreme-react@18.2', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.6/dist/quill.js', // 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 } });