# scheduler-external-drag-and-drop

> Scheduler accepts drag-and-drop from an external tree view into its time slots.

**Framework:** react  **Component:** Scheduler  **Variant:** external-drag-and-drop

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/react/ts/scheduler-external-drag-and-drop.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-navigations @syncfusion/ej2-react-navigations @syncfusion/ej2-react-schedule
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/scheduler-external-drag-and-drop/Scheduler.tsx

```tsx
import { useRef } from 'react';
import { ScheduleComponent, type TreeViewArgs, ResourcesDirective, ResourceDirective, ViewsDirective, ViewDirective, type ResourceDetails, Inject, TimelineViews, Resize, DragAndDrop, TimelineMonth, type ActionEventArgs, type CellClickEventArgs } from '@syncfusion/ej2-react-schedule';
import { extend, closest, remove, addClass } from '@syncfusion/ej2-base';
import { type DragAndDropEventArgs } from '@syncfusion/ej2-navigations';
import { TreeViewComponent } from '@syncfusion/ej2-react-navigations';
import { waitingList, hospitalData } from '../datasource/scheduler-data';

const SAMPLE_CSS = `
.drag-sample-wrapper {
  display: -ms-flexbox;
  display: flex;
}
.schedule-container {
  padding-right: 10px;
  width: 100%;
}
.title-container {
  padding-bottom: 10px;
}
.title-text {
  font-size: 18px;
  margin: 0px;
  font-weight: bold;
  text-align: center;
  line-height: 1.1;
}
.treeview-external-drag #waiting {
  height: 100%;
  padding: 0;
}
.treeview-external-drag #waitdetails {
  width: 95%;
  float: left;
  height: 100%;
  padding: 0;
}
.treeview-external-drag #waitlist {
  width: 100%;
  height: 50%;
  font-weight: bold;
  font-family: "Segoe UI";
  font-size: 12px;
  padding: 5px 0 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.treeview-external-drag #waitcategory {
  height: 50%;
  font-family: "Segoe UI";
  font-size: 10px;
  opacity: 0.6;
  padding-left: 10px;
  padding-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.treeview-external-drag .e-list-text, .treeview-external-drag.e-rtl .e-list-text, .e-bigger .treeview-external-drag .e-list-text, .e-bigger .treeview-external-drag.e-rtl .e-list-text {
  border: 0.5px solid #E1E7EC;
  height: 50px;
  line-height: 15px !important;
  padding: 0 5px;
  width: 220px;
}
.treeview-external-drag .e-list-parent, .treeview-external-drag.e-rtl .e-list-parent, .e-bigger .treeview-external-drag .e-list-parent, .e-bigger .treeview-external-drag.e-rtl .e-list-parent {
  height: 100%;
  padding: 0 2px;
}
.treeview-external-drag .e-list-item, .e-bigger .treeview-external-drag .e-list-item {
  height: 100%;
  padding: 0 0 5px 0;
}
.treeview-external-drag .e-fullrow, .e-bigger .treeview-external-drag .e-fullrow {
  height: 55px;
}
.treeview-external-drag .e-list-item.e-hover>.e-fullrow, .treeview-external-drag .e-list-item.e-active>.e-fullrow, .treeview-external-drag .e-list-item.e-active.e-hover>.e-fullrow, .e-bigger .treeview-external-drag .e-list-item.e-hover>.e-fullrow, .e-bigger .treeview-external-drag .e-list-item.e-active>.e-fullrow, .e-bigger .treeview-external-drag .e-list-item.e-active.e-hover>.e-fullrow {
  background-color: transparent;
  border-color: transparent;
  box-shadow: none !important;
}
.treeview-external-drag .e-text-content, .e-bigger .treeview-external-drag .e-text-content, .treeview-external-drag.e-rtl .e-text-content, .e-bigger .treeview-external-drag.e-rtl .e-text-content {
  padding: 0;
  background-color: inherit;
}
.e-drag-item.e-treeview.treeview-external-drag, .e-bigger .e-drag-item.e-treeview.treeview-external-drag {
  padding: 0 !important;
}
.e-device-hover {
  background-color: #e0e0e0 !important;
}
.e-disble-not-allowed {
  cursor: unset !important;
}
.e-drag-item.treeview-external-drag .e-icon-expandable {
  display: none;
}
`;

/**
 * schedule resources group-editing sample
 */

const ExternalDragDrop = () => {
  let scheduleObj = useRef<ScheduleComponent>(null);
  let treeObj = useRef<TreeViewComponent>(null);
  let isTreeItemDropped: boolean = false;
  let draggedItemId: string = '';
  const allowDragAndDrops: boolean = true;
  const fields: Record<string, any> = { dataSource: waitingList, id: 'Id', text: 'Name' };
  const data: Record<string, any>[] = extend([], hospitalData, undefined, true) as Record<string, any>[];
  const departmentData: Record<string, any>[] = [
    { Text: 'GENERAL', Id: 1, Color: '#bbdc00' },
    { Text: 'DENTAL', Id: 2, Color: '#9e5fff' }
  ];
  const consultantData: Record<string, any>[] = [
    { Text: 'Alice', Id: 1, GroupId: 1, Color: '#bbdc00', Designation: 'Cardiologist' },
    { Text: 'Nancy', Id: 2, GroupId: 2, Color: '#9e5fff', Designation: 'Orthodontist' },
    { Text: 'Robert', Id: 3, GroupId: 1, Color: '#bbdc00', Designation: 'Optometrist' },
    { Text: 'Robson', Id: 4, GroupId: 2, Color: '#9e5fff', Designation: 'Periodontist' },
    { Text: 'Laura', Id: 5, GroupId: 1, Color: '#bbdc00', Designation: 'Orthopedic' },
    { Text: 'Margaret', Id: 6, GroupId: 2, Color: '#9e5fff', Designation: 'Endodontist' }
  ];

  const getConsultantName = (value: ResourceDetails | TreeViewArgs): string => {
    const textField = (value as ResourceDetails).resource?.textField;
    return (value as ResourceDetails).resourceData?.[textField ?? ''] as string;
  }

  const getConsultantImage = (value: ResourceDetails): string => {
    return getConsultantName(value).toLowerCase();
  }

  const getConsultantDesignation = (value: ResourceDetails): string => {
    return (value as ResourceDetails).resourceData.Designation as string;
  }

  const resourceHeaderTemplate = (props: any)  => {
    return (
      <div className="template-wrap">
        <div className="specialist-category">
          <div className={"specialist-image " + getConsultantImage(props)}></div>
          <div className="specialist-name"> {getConsultantName(props)}</div>
          <div className="specialist-designation">{getConsultantDesignation(props)}</div>
        </div>
      </div>
    );
  }

  const treeTemplate = (props: any) => {
    return (
      <div id="waiting">
        <div id="waitdetails">
          <div id="waitlist">{props.Name}</div>
          <div id="waitcategory">{props.DepartmentName} - {props.Description}</div>
        </div>
      </div>
    );
  }

  const onItemSelecting = (args: any): void => {
    args.cancel = true;
  }

  const onTreeDrag = (event: any): void => {
    if (scheduleObj.current?.isAdaptive) {
      let classElement: HTMLElement | null = scheduleObj.current.element.querySelector('.e-device-hover');
      if (classElement) {
        classElement.classList.remove('e-device-hover');
      }
      if (event.target.classList.contains('e-work-cells')) {
        addClass([event.target], 'e-device-hover');
      }
    }
  }

  const onActionBegin = (event: ActionEventArgs): void => {
    if (event.requestType === 'eventCreate' && isTreeItemDropped && treeObj.current) {
      let treeViewData: Record<string, any>[] = treeObj.current.fields.dataSource as Record<string, any>[];
      const filteredPeople: Record<string, any>[] = treeViewData.filter((item: any) => item.Id !== parseInt(draggedItemId, 10));
      treeObj.current.fields.dataSource = filteredPeople;
      let elements: NodeListOf<HTMLElement> = document.querySelectorAll('.e-drag-item.treeview-external-drag');
      for (let i: number = 0; i < elements.length; i++) {
        remove(elements[i]);
      }
    }
  }

  const onTreeDragStop = (event: DragAndDropEventArgs): void => {
    let treeElement: Element = closest(event.target, '.e-treeview');
    let classElement: HTMLElement | null | undefined = scheduleObj.current?.element.querySelector('.e-device-hover');
    if (classElement) {
      classElement.classList.remove('e-device-hover');
    }
    if (!treeElement) {
      event.cancel = true;
      let scheduleElement: Element = closest(event.target, '.e-content-wrap');
      if (scheduleElement && treeObj.current && scheduleObj.current) {
        let treeviewData: Record<string, any>[] = treeObj.current.fields.dataSource as Record<string, any>[];
        if (event.target.classList.contains('e-work-cells')) {
          const filteredData: Record<string, any>[] = treeviewData.filter((item: any) => item.Id === parseInt(event.draggedNodeData.id as string, 10));
          let cellData: CellClickEventArgs = scheduleObj.current.getCellDetails(event.target);
          let resourceDetails: ResourceDetails = scheduleObj.current.getResourcesByIndex(cellData.groupIndex ?? 0);
          let eventData: Record<string, any> = {
            Name: filteredData[0].Name,
            StartTime: cellData.startTime,
            EndTime: cellData.endTime,
            IsAllDay: cellData.isAllDay,
            Description: filteredData[0].Description,
            DepartmentID: resourceDetails.resourceData.GroupId,
            ConsultantID: resourceDetails.resourceData.Id
          };
          scheduleObj.current.openEditor(eventData, 'Add', true);
          isTreeItemDropped = true;
          draggedItemId = event.draggedNodeData.id as string;
        }
      }
    }
    document.body.classList.remove('e-disble-not-allowed');
  }

  const onTreeDragStart = () => {
    document.body.classList.add('e-disble-not-allowed');
  }

  return (
    <div>
      <style>{SAMPLE_CSS}</style>
      <div className='schedule-control-section'>
      <div className='col-lg-12 control-section'>
        <div className='control-wrapper drag-sample-wrapper'>
          <div className="schedule-container">
            <div className="title-container">
              <h1 className="title-text">Doctor's Appointments</h1>
            </div>
            <ScheduleComponent ref={scheduleObj} cssClass='schedule-drag-drop' width='100%' height='650px' selectedDate={new Date(2021, 7, 2)} currentView='TimelineDay' resourceHeaderTemplate={resourceHeaderTemplate} eventSettings={{ dataSource: data, fields: { subject: { title: 'Patient Name', name: 'Name' }, startTime: { title: "From", name: "StartTime" }, endTime: { title: "To", name: "EndTime" }, description: { title: 'Reason', name: 'Description' } } }} group={{ enableCompactView: false, resources: ['Departments', 'Consultants'] }} actionBegin={onActionBegin} >
              <ResourcesDirective>
                <ResourceDirective field='DepartmentID' title='Department' name='Departments' allowMultiple={false} dataSource={departmentData} textField='Text' idField='Id' colorField='Color' />
                <ResourceDirective field='ConsultantID' title='Consultant' name='Consultants' allowMultiple={false} dataSource={consultantData} textField='Text' idField='Id' groupIDField="GroupId" colorField='Color' />
              </ResourcesDirective>
              <ViewsDirective>
                <ViewDirective option='TimelineDay' />
                <ViewDirective option='TimelineMonth' />
              </ViewsDirective>
              <Inject services={[TimelineViews, TimelineMonth, Resize, DragAndDrop]} />
            </ScheduleComponent>
          </div>
          <div className="treeview-container">
            <div className="title-container">
              <h1 className="title-text">Waiting List</h1>
            </div>
            <TreeViewComponent ref={treeObj} cssClass='treeview-external-drag' dragArea=".drag-sample-wrapper" nodeTemplate={treeTemplate} fields={fields} nodeDragStop={onTreeDragStop} nodeSelecting={onItemSelecting} nodeDragging={onTreeDrag} nodeDragStart={onTreeDragStart} allowDragAndDrop={allowDragAndDrops} />
          </div>
        </div>
      </div>
    </div>
    </div>
  );
}
export default ExternalDragDrop;
```
