DevExtreme jQuery/JS - Assign Appointments to Resources
The Scheduler widget allows you to assign appointments to a set of predefined resources. Consider the following example: in an educational center lectures are held in two rooms. In scheduling terms, a lecture is an appointment, a room is a resource instance, and all rooms are considered the resource kind.
To define resource kinds, assign an array of objects specifying them to the resources option. Each object must have at least the following fields.
- dataSource
All available resource instances (for example, room101, room102). For information on different techniques that you can use to provide data for resources, see the Data Binding topic. - fieldExpr
The data field that binds an appointment to a resource instance.
Note that every resource instance should have a special structure that includes id, color and text fields. If the structure of your resources differs, set the valueExpr, colorExpr and displayExpr options as shown in the code above.
API
Each resource kind has the fieldExpr option. To associate an appointment with a resource, include a field specified in the fieldExpr option into the appointment's data object.
The following image illustrates appointments assigned to different resources. Each color indicates a relation to a definite resource.
Appointments with several resource kinds are colored like the last one in the resources array. To color appointments in colors of another resource kind, set its useColorAsDefault option to true.
- var resources = [{
- fieldExpr: 'roomId',
- dataSource: [
- { id: 1, text: 'Room101', color: 'green' },
- { id: 2, text: 'Room102', color: 'red' },
- // ...
- ],
- useColorAsDefault: true
- }, {
- fieldExpr: 'teacherId',
- dataSource: [
- { id: 1, text: 'Sandra Johnson', color: 'yellow' },
- { id: 2, text: 'John Heart', color: 'blue' },
- // ...
- ]
- }];
User Interaction
The Scheduler shows all available resource kinds in the appointment details form. By default, the widget allows a user to assign only a single resource of one kind.
To allow multiple resources, assign true to the allowMultiple option of the corresponding resource kind.
- var resources = [
- { fieldExpr: 'roomId', dataSource: roomsDataSource },
- { fieldExpr: 'teacherId', dataSource: teachersDataSource, allowMultiple: true }
- ];
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.