-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
- Overview
-
Action Sheet
-
Button
- Floating Action Button
- Drop Down Button
-
Context Menu
-
List
-
Lookup
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
React Scheduler - Disabled Date/Time Ranges
This demo shows how to disable specific days, dates, and times when a user cannot schedule an appointment. In the demo, appointments are disabled for weekends, certain individual dates (e.g., May 25th), and the time period from 12:00pm to 1:00pm.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
/* eslint-disable func-style */
import React, { useCallback, useMemo, useState } from 'react';
import Scheduler, { SchedulerTypes } from 'devextreme-react/scheduler';
import notify from 'devextreme/ui/notify';
import { FormRef } from 'devextreme-react/form';
import { data, holidays } from './data.ts';
import Utils from './utils.ts';
import DataCell from './DataCell.tsx';
import DataCellMonth from './DataCellMonth.tsx';
import DateCell from './DateCell.tsx';
import TimeCell from './TimeCell.tsx';
const currentDate = new Date(2021, 3, 27);
const views: SchedulerTypes.ViewType[] = ['workWeek', 'month'];
const ariaDescription = () => {
const disabledDates = holidays
.filter((date) => !Utils.isWeekend(date))
.map((date) => new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
);
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
};
const notifyDisableDate = () => {
notify('Cannot create or move an appointment/event to disabled time/date regions.', 'warning', 1000);
};
const onContentReady = (e: SchedulerTypes.ContentReadyEvent) => {
setComponentAria(e.component?.$element());
}
const applyDisableDatesToDateEditors = (form: ReturnType<FormRef['instance']>) => {
const startDateEditor = form.getEditor('startDate');
startDateEditor?.option('disabledDates', holidays);
const endDateEditor = form.getEditor('endDate');
endDateEditor?.option('disabledDates', holidays);
};
const onAppointmentFormOpening = (e: SchedulerTypes.AppointmentFormOpeningEvent) => {
if (e.appointmentData?.startDate) {
const startDate = new Date(e.appointmentData.startDate);
if (!Utils.isValidAppointmentDate(startDate)) {
e.cancel = true;
notifyDisableDate();
}
applyDisableDatesToDateEditors(e.form);
}
};
const onAppointmentAdding = (e: SchedulerTypes.AppointmentAddingEvent) => {
const isValidAppointment = Utils.isValidAppointment(e.component, e.appointmentData);
if (!isValidAppointment) {
e.cancel = true;
notifyDisableDate();
}
};
const onAppointmentUpdating = (e: SchedulerTypes.AppointmentUpdatingEvent) => {
const isValidAppointment = Utils.isValidAppointment(e.component, e.newData);
if (!isValidAppointment) {
e.cancel = true;
notifyDisableDate();
}
};
const setComponentAria = (element) => {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${ariaDescription()}`);
}
const App = () => {
const [currentView, setCurrentView] = useState<SchedulerTypes.ViewType>(views[0]);
const DataCellComponent = useMemo(() => (
currentView === 'month' ? DataCellMonth : DataCell
), [currentView]);
const onCurrentViewChange = useCallback((value) => setCurrentView(value), [setCurrentView]);
const renderDateCell = useCallback((itemData) => (
<DateCell itemData={itemData} currentView={currentView} />
), []);
return (
<Scheduler
dataSource={data}
views={views}
defaultCurrentDate={currentDate}
currentView={currentView}
onCurrentViewChange={onCurrentViewChange}
height={730}
showAllDayPanel={false}
firstDayOfWeek={0}
startDayHour={9}
endDayHour={19}
dataCellComponent={DataCellComponent}
dateCellRender={renderDateCell}
timeCellComponent={TimeCell}
onContentReady={onContentReady}
onAppointmentFormOpening={onAppointmentFormOpening}
onAppointmentAdding={onAppointmentAdding}
onAppointmentUpdating={onAppointmentUpdating}
/>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
To implement this functionality in your application, follow the steps below:
-
Implement custom date/time validation functions
These functions should check whether a date or time is available. This demo includes the date/time validation functions listed below. In your application, they can be different.isValidAppointment
Prepares data and begins validation.isValidAppointmentInterval
Validates a date/time interval.isValidAppointmentDate
Calls theisHoliday
,isWeekend
, andisDinner
functions.isHoliday
/isWeekend
/isDinner
Check whether a date/time interval is a holiday, a weekend, or dinner time.
-
Validate appointments before they are created or updated
Before an appointment is created or updated, the Scheduler executes the onAppointmentAdding and onAppointmentUpdating functions. Use them to start validation. If a date or time is invalid,cancel
the creation or update. Implement the same logic in the onAppointmentFormOpening function so that users cannot open the appointment details form for a disabled date or time. -
Customize the appointment details form
The appointment details form includes two calendars that allow users to select an appointment's start and end date/time. You should also disable dates in these calendars. Review theapplyDisableDatesToDateEditors
function to see how this is done. Call this function from onAppointmentFormOpening. -
Customize the timetable appearance
Use templates to customize the appearance of data cells (dataCellTemplate), time cells (timeCellTemplate), and date cells (dateCellTemplate). In this demo, date cell customization is visible only in the Month view. To switch to this view, use the view switcher in the Scheduler's upper right corner.