简体   繁体   English

拖放外部事件FullCalendar React-Wrapper

[英]Drag And Drop External Events FullCalendar React-Wrapper

I am not being able to drop external events on the calendar. 我无法在日历上删除外部事件。 The calendar renders correctly, and the functions select and eventClick works as expected. 日历可以正确呈现,并且功能selecteventClick可以正常工作。 I wanted to know now how to be able to drop external events in the calendar... I've been reading the fullcalendar.io documentation and I'm not really able to do what I want. 我现在想知道如何能够在日历中删除外部事件...我一直在阅读fullcalendar.io文档 ,但我确实无法做我想做的事情。

The setting I am using is as follows: 我使用的设置如下:

<FullCalendar 
    id="calendario"
    header={{
        left: 'prev,next today myCustomButton',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    }}
    navLinks={true}
    nowIndicator={true}
    viewRender={(view, element) => {
        this.handleChangeView(view);
    }}
    selectable={true}
    editable={true}
    droppable={true}
    eventDrop={function(eventBj, date) {
        console.log('eventDrop function');
    }}
    drop={(date, jsEvent, ui, resourceId) => {
        console.log('drop function');
    }}
    select={(start, end, allDay) => {
        this.handleSelect(start, end, allDay);
    }}
    eventClick={(calEvent, jsEvent, view) => {
        this.handleClick(calEvent, jsEvent, view);
    }}
    events={events}
/>

I'm including jQuery-UI and the event triggers the draggable , I can hover with the external-event over the calendar. 我包括jQuery-UI,事件触发了draggable ,我可以将外部事件悬停在日历上。

EDIT 编辑

The drag effect is initiated in the componentDidMount lifecycle. 拖动效果在componentDidMount生命周期中启动。

Note: I use a minifier in setting innerHTML, but I'll put it here without a minifier to understand it better. 注意:我在设置innerHTML时使用了一个缩小器,但是我将它放在此处而不使用缩小器来更好地理解它。

componentDidMount() {
    const s = document.createElement('script');
    s.type = 'text/javascript';
    s.innerHTML = "$('.calendar-events').each(function() {
        $(this).data('event', {
            title: $.trim($(this).text()),
            stick: true
        });
        $(this).draggable({
            zIndex: 999,
            revert: true,
            revertDuration: 0
        })
    });";
    document.body.appendChild(s);
}

I have 0 errors and 0 warnings in console. 我在控制台中有0个错误和0个警告。 And the drag effect happens like it should :/ 拖动效果会像它应该的那样发生:/

EDIT-2 编辑-2

I'm currently using 2 classes to render the calendar: 我目前正在使用2个类来呈现日历:

1. 1。

class Calendario extends Component {
  componentDidMount() {
    const s = document.createElement('script');
    s.type = 'text/javascript';
    s.innerHTML =
      "$('.calendar-events').each(function(){$(this).data('event',{title:$.trim($(this).text()),stick:!0}),$(this).draggable({zIndex:999,revert:!0,revertDuration:0})});";
    document.body.appendChild(s);
  }

  render() {
    return (
      <>
        <Grid container spacing={16} >
          <Grid item md={3}>
            Eventos
            <div className="calendar-events">
              <i className="fa fa-circle text-info" /> Consultas
            </div>
          </Grid>
          <Grid item md={9} style={{ minHeight: '500px' }}>
            <FullCalendarComponent />
          </Grid>
        </Grid>
      </>
    );
  }
}

Second 第二

export class FullCalendarComponent extends Component {
  state = {
    view: 'agendaWeek',
    events: [
      {
        title: 'Static Event 1',
        start: '2018-11-20T16:00:00'
      },
      {
        title: 'Static Event 2',
        start: '2018-11-21T16:00:00',
        end: '2018-11-21T18:00:00'
      },
      {
        title: 'Static Event 3',
        start: '2018-11-20T11:00:00',
        end: '2018-11-20T13:00:00'
      },
      {
        title: 'Static Event 4',
        start: '2018-11-22T14:00:00',
        end: '2018-11-22T16:00:00'
      }
    ]
  };

  shouldComponentUpdate(nextProps, nextState) {
    if (this.state.events !== nextState.events) {
      return true;
    }
    return false;
  }

  handleDrop = (eventObj, date) => {
    console.group('onDrop');
    console.log('date');
    console.dir(date);
    console.groupEnd();
  };

  handleSelect = (start, end, allDay) => {
    console.group('select');
    console.log('start');
    console.dir(start);
    console.dir('end');
    console.dir(end);
    console.groupEnd();
  };

  handleClick = (calEvent, jsEvent, view) => {
    console.group('click');
    console.log('calEvent');
    console.dir(calEvent);
    console.groupEnd();
  };

  handleChangeView = view => e => {
    e.preventDefault();
    this.setState({
      view: view.name
    });
  };

  render() {
    const { events, view } = this.state;
    return (
      <FullCalendar 
        id="calendario"
        header={{
            left: 'prev,next today myCustomButton',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        }}
        navLinks={true}
        nowIndicator={true}
        viewRender={(view, element) => {
            this.handleChangeView(view);
        }}
        selectable={true}
        editable={true}
        droppable={true}
        eventDrop={function(eventBj, date) {
            console.log('eventDrop function');
        }}
        drop={(date, jsEvent, ui, resourceId) => {
            console.log('drop function');
        }}
        select={(start, end, allDay) => {
            this.handleSelect(start, end, allDay);
        }}
        eventClick={(calEvent, jsEvent, view) => {
            this.handleClick(calEvent, jsEvent, view);
        }}
        events={events}
      />
    );
  }
}

In my index.html file, I'm including scripts to jquery.min.js and jquery-ui.min.js 在我的index.html文件中,我包含了jquery.min.jsjquery-ui.min.js脚本

The callback eventDrop is only triggered for internal event drops. 仅针对内部事件删除触发回调eventDrop。 You need to add the callback eventReceive for external event drops. 您需要为外部事件删除添加回调eventReceive。 Then you can at least tell if fullcalendar is detecting the drops. 然后,您至少可以确定fullcalendar是否正在检测墨滴。 I also have my fullcalendar inside a React wrapper, and after some trial and error, was able to make events draggable and it works perfectly! 我还把我的全日历放在一个React包装器中,经过一番尝试和错误之后,它能够使事件变为可拖动状态,并且效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM