# Slot Selection

The Scheduler enables the user to choose time and day slots, and to select time ranges by clicking and dragging over a set of slots.

Slot selection is available for all Scheduler views except for the [`Agenda`](https://www.telerik.com/kendo-angular-ui/components/scheduler/views/agenda) view as it displays events and only allows the user to select them.

## Built-in Directive

To enable the built-in slot selection, use the [`kendoSchedulerSlotSelectable`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective) directive.

The directive internally handles the `slotDragStart`, `slotDrag`, and `slotDragEnd` events of the Scheduler and manages the selection automatically. The directive emits a [`slotSelectionChange`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective#slotselectionchange) event when a new selection is made through user interaction.

The [`kendoSchedulerSlotSelectable`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective) directive also allows programmatic selection through its [`slotSelection`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective#slotselection) binding. `kendoSchedulerSlotSelectable` supports both one-way and two-way binding.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/scheduler/slot-selection/directive/source.txt)

## Custom Callback

To enable a custom slot selection, use the following configuration:

1. Set the [`selectable`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#selectable) input of the Scheduler to `true`. It is set to `false` by default.
2. Pass a custom [`isSlotSelected`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#isslotselected) callback to the Scheduler.

When [`selectable`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#selectable) is set to `true`, the Scheduler component will emit the following events:

* [`slotDragStart`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#slotdragstart)—Fires when a mouse drag is initiated.
* [`slotDrag`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#slotdrag)—Fires when the user is dragging over slots.
* [`slotDragEnd`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#slotdragend)—Fires when the drag is over.

You can use these events to obtain the `start` and `end` of the selection. The user-defined [`isSlotSelected`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#isslotselected) callback is executed for every slot in the view. If the function returns `true` for a given slot, the slot will be visually styled as selected.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/scheduler/slot-selection/manual/source.txt)

## Creating Events from Selection

You can create new events inside the Scheduler by dragging the cursor through the slots. This provides better visual indication of where the event will be created and automatically set its `start` and `end` date.

To provide a visual representation of the newly created event:

1. Handle the [`slotSelectionChange`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective#slotselectionchange) to check the selected slots and create the necessary `FormGroup`.
2. Use the [`addEvent`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent#addevent) method to add the new event.

The following example demonstrates the suggestion in action.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/scheduler/slot-selection/event-from-selection/source.txt)

## Suggested Links

* [Angular Scheduler Overview](https://www.telerik.com/kendo-angular-ui/components/scheduler)
* [`kendoSchedulerSlotSelectable`](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/slotselectabledirective)
* [API Reference of the SchedulerComponent](https://www.telerik.com/kendo-angular-ui/components/scheduler/api/schedulercomponent)
