Your search did not match any results.
Calendar

Calendar

Documentation

The Calendar is a widget that displays a calendar and allows an end user to select the required date within a specified date range.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import { CheckBox, SelectBox, DateBox, Calendar } from 'devextreme-react'; class App extends React.Component { constructor() { super(); this.state = { minDateValue: null, maxDateValue: null, disabledDates: null, firstDay: 0, currentValue: new Date(), cellTemplate: null, disabled: false, zoomLevel: 'month' }; this.onCurrentValueChanged = this.onCurrentValueChanged.bind(this); this.onDisabledChanged = this.onDisabledChanged.bind(this); this.onZoomLevelValueChanged = this.onZoomLevelValueChanged.bind(this); this.onZoomLevelChanged = this.onZoomLevelChanged.bind(this); this.setMinDate = this.setMinDate.bind(this); this.setMaxDate = this.setMaxDate.bind(this); this.disableWeekend = this.disableWeekend.bind(this); this.setFirstDay = this.setFirstDay.bind(this); this.useCellTemplate = this.useCellTemplate.bind(this); } render() { const { currentValue, minDateValue, maxDateValue, disabledDates, firstDay, disabled, zoomLevel, cellTemplate } = this.state; return ( <div id={'calendar-demo'}> <div className={'widget-container'}> <Calendar id={'calendar-container'} value={currentValue} onValueChanged={this.onCurrentValueChanged} onOptionChanged={this.onZoomLevelChanged} min={minDateValue} max={maxDateValue} disabledDates={disabledDates} firstDayOfWeek={firstDay} disabled={disabled} zoomLevel={zoomLevel} cellComponent={cellTemplate} /> </div> <div className={'options'}> <div className={'caption'}>Options</div> <div className={'option'}> <CheckBox defaultValue={false} text={'Specified min value'} onValueChanged={this.setMinDate} /> </div> <div className={'option'}> <CheckBox defaultValue={false} text={'Specified max value'} onValueChanged={this.setMaxDate} /> </div> <div className={'option'}> <CheckBox defaultValue={false} text={'Disable weekend'} onValueChanged={this.disableWeekend} /> </div> <div className={'option'}> <CheckBox defaultValue={false} text={'Monday as the first day of a week'} onValueChanged={this.setFirstDay} /> </div> <div className={'option'}> <CheckBox defaultValue={false} text={'Use the Custom Cell Template'} onValueChanged={this.useCellTemplate} /> </div> <div className={'option'}> <CheckBox value={disabled} text={'Disabled'} onValueChanged={this.onDisabledChanged} /> </div> <div className={'option'}> <span>Zoom level</span> <SelectBox id={'zoom-level'} dataSource={['month', 'year', 'decade', 'century']} value={zoomLevel} onValueChanged={this.onZoomLevelValueChanged} /> </div> <div className={'option'}> <span>Selected date</span> <DateBox id={'selected-date'} value={currentValue} width={'100%'} onValueChanged={this.onCurrentValueChanged} /> </div> </div> </div> ); } onCurrentValueChanged(e) { this.setState({ currentValue: e.value }); } onDisabledChanged(e) { this.setState({ disabled: e.value }); } onZoomLevelValueChanged(e) { this.setState({ zoomLevel: e.value }); } onZoomLevelChanged(e) { if(e.name === 'zoomLevel') { this.setState({ zoomLevel: e.value }); } } setMinDate(e) { this.setState({ minDateValue: e.value ? new Date((new Date).getTime() - 1000 * 60 * 60 * 24 * 3) : undefined }); } setMaxDate(e) { this.setState({ maxDateValue: e.value ? new Date((new Date).getTime() + 1000 * 60 * 60 * 24 * 3) : undefined }); } disableWeekend(e) { this.setState({ disabledDates: e.value ? (data) => data.view === 'month' && isWeekend(data.date) : undefined }); } setFirstDay(e) { this.setState({ firstDay: e.value ? 1 : 0 }); } useCellTemplate(e) { this.setState({ cellTemplate: e.value ? CustomCell : undefined }); } } function CustomCell(cell) { return ( <span className={getCellCssClass(cell.date)}> { cell.text } </span> ); } function getCellCssClass(date) { let cssClass = ''; const holydays = [[1, 0], [4, 6], [25, 11]]; if(isWeekend(date)) { cssClass = 'weekend'; } holydays.forEach((item) => { if(date.getDate() === item[0] && date.getMonth() === item[1]) { cssClass = 'holyday'; return false; } }); return cssClass; } function isWeekend(date) { const day = date.getDay(); return day === 0 || day === 6; } 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/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="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.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>
.widget-container { margin-right: 320px; } #calendar-container { margin: auto; } .dx-calendar-cell:not(.dx-calendar-other-month) .weekend, .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { text-shadow: none; font-weight: bold; } .dx-calendar-cell:not(.dx-calendar-other-month) .weekend { color: #3030FF; } .dx-state-disabled.dx-calendar .dx-calendar-cell:not(.dx-calendar-other-month) .weekend { color: #8080FF; } .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { color: #FF3030; } .dx-state-disabled.dx-calendar .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { color: #FF8080; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); position: absolute; right: 0; top: 0; bottom: 0; width: 260px; } .caption { font-weight: 500; font-size: 18px; } .option { margin-top: 10px; }
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 } });