How merge events in fullcalendar on select/drag?
I have fullcalendar with agendaweek view. I have events in table coming from server. I want to do the next thing: user can select few events in the table with select
event and when he do it, I want to add green border over selected area.
http://prntscr.com/lhkp9y
I found one way - it is to merge selected events into one, but it is not so easy if starting point is over existing event. On the screen starting point - is empty timeslot.
What I have now: If events are editable:false
in the table, and I start to select and starting point is over existing event, nothing happens. If starting point is - empty timeslot, it works
If events are editable:true
in the table, and I start to select and starting point - is existing event, this event stick to cursor and start to move which is not good. I want existing event stay on the same place.
Here is my calendar code
$('#calendar').fullCalendar(
defaultView: 'agendaWeek',
firstDay: 1,
navLinks: false,
header: false,
selectable: true,
eventOverlap: true,
selectOverlap: function (event)
// check is allowed to select next timeslot ot not
return !event.closed;
,
selectHelper: true,
allDaySlot: true,
minTime: self.minTime,
maxTime: self.maxTime,
slotLabelInterval: '00:30:00',
viewSubSlotLabel: true,
slotLabelFormat: 'h:mm a',
editable: true,
events: events,
select: function (start, end, jsEvent, view)
// merge selected events into one
self.mergeEvents();
,
eventDragStart: function (event, jsEvent, ui, view)
// I WANT TO CANCEL DRAG, BUT IT DOESNT WORK
return false;
);
javascript jquery fullcalendar
add a comment |
I have fullcalendar with agendaweek view. I have events in table coming from server. I want to do the next thing: user can select few events in the table with select
event and when he do it, I want to add green border over selected area.
http://prntscr.com/lhkp9y
I found one way - it is to merge selected events into one, but it is not so easy if starting point is over existing event. On the screen starting point - is empty timeslot.
What I have now: If events are editable:false
in the table, and I start to select and starting point is over existing event, nothing happens. If starting point is - empty timeslot, it works
If events are editable:true
in the table, and I start to select and starting point - is existing event, this event stick to cursor and start to move which is not good. I want existing event stay on the same place.
Here is my calendar code
$('#calendar').fullCalendar(
defaultView: 'agendaWeek',
firstDay: 1,
navLinks: false,
header: false,
selectable: true,
eventOverlap: true,
selectOverlap: function (event)
// check is allowed to select next timeslot ot not
return !event.closed;
,
selectHelper: true,
allDaySlot: true,
minTime: self.minTime,
maxTime: self.maxTime,
slotLabelInterval: '00:30:00',
viewSubSlotLabel: true,
slotLabelFormat: 'h:mm a',
editable: true,
events: events,
select: function (start, end, jsEvent, view)
// merge selected events into one
self.mergeEvents();
,
eventDragStart: function (event, jsEvent, ui, view)
// I WANT TO CANCEL DRAG, BUT IT DOESNT WORK
return false;
);
javascript jquery fullcalendar
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46
add a comment |
I have fullcalendar with agendaweek view. I have events in table coming from server. I want to do the next thing: user can select few events in the table with select
event and when he do it, I want to add green border over selected area.
http://prntscr.com/lhkp9y
I found one way - it is to merge selected events into one, but it is not so easy if starting point is over existing event. On the screen starting point - is empty timeslot.
What I have now: If events are editable:false
in the table, and I start to select and starting point is over existing event, nothing happens. If starting point is - empty timeslot, it works
If events are editable:true
in the table, and I start to select and starting point - is existing event, this event stick to cursor and start to move which is not good. I want existing event stay on the same place.
Here is my calendar code
$('#calendar').fullCalendar(
defaultView: 'agendaWeek',
firstDay: 1,
navLinks: false,
header: false,
selectable: true,
eventOverlap: true,
selectOverlap: function (event)
// check is allowed to select next timeslot ot not
return !event.closed;
,
selectHelper: true,
allDaySlot: true,
minTime: self.minTime,
maxTime: self.maxTime,
slotLabelInterval: '00:30:00',
viewSubSlotLabel: true,
slotLabelFormat: 'h:mm a',
editable: true,
events: events,
select: function (start, end, jsEvent, view)
// merge selected events into one
self.mergeEvents();
,
eventDragStart: function (event, jsEvent, ui, view)
// I WANT TO CANCEL DRAG, BUT IT DOESNT WORK
return false;
);
javascript jquery fullcalendar
I have fullcalendar with agendaweek view. I have events in table coming from server. I want to do the next thing: user can select few events in the table with select
event and when he do it, I want to add green border over selected area.
http://prntscr.com/lhkp9y
I found one way - it is to merge selected events into one, but it is not so easy if starting point is over existing event. On the screen starting point - is empty timeslot.
What I have now: If events are editable:false
in the table, and I start to select and starting point is over existing event, nothing happens. If starting point is - empty timeslot, it works
If events are editable:true
in the table, and I start to select and starting point - is existing event, this event stick to cursor and start to move which is not good. I want existing event stay on the same place.
Here is my calendar code
$('#calendar').fullCalendar(
defaultView: 'agendaWeek',
firstDay: 1,
navLinks: false,
header: false,
selectable: true,
eventOverlap: true,
selectOverlap: function (event)
// check is allowed to select next timeslot ot not
return !event.closed;
,
selectHelper: true,
allDaySlot: true,
minTime: self.minTime,
maxTime: self.maxTime,
slotLabelInterval: '00:30:00',
viewSubSlotLabel: true,
slotLabelFormat: 'h:mm a',
editable: true,
events: events,
select: function (start, end, jsEvent, view)
// merge selected events into one
self.mergeEvents();
,
eventDragStart: function (event, jsEvent, ui, view)
// I WANT TO CANCEL DRAG, BUT IT DOESNT WORK
return false;
);
javascript jquery fullcalendar
javascript jquery fullcalendar
asked Nov 12 '18 at 22:20
WhatIsHTMLWhatIsHTML
3031315
3031315
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46
add a comment |
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46
add a comment |
1 Answer
1
active
oldest
votes
Try it, hope it's fine for you.
select: function (start, end, jsEvent, view)
var diffmin = (new Date(end).getTime()/1000 - new Date(start).getTime()/1000)/60;
var title = diffmin+' min';
var eventData;
// some users click 1 slot, then the following, so we have 2 events each 30 min instead of 60 min
// merge both events into one
var eventmerge = false;
$.each(allevents, function( index, eventitem )
if(eventitem!==null && typeof eventitem != 'undefined')
// if start time of new event (2nd slot) is end time of existing event (1st slot)
if( moment(start).format('YYYY-MM-DD HH:mm') == moment(eventitem.end).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets end data of new merging event
eventitem.end = end;
// if end time of new event (1st slot) is start time of existing event (2nd slot)
else if( moment(end).format('YYYY-MM-DD HH:mm') == moment(eventitem.start).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets start data of new merging event
eventitem.start = start;
if(eventmerge)
// recalculate
var diffmin = (new Date(eventitem.end).getTime()/1000 - new Date(eventitem.start).getTime()/1000)/60;
eventitem.title = diffmin+' min';
// copy to eventData
eventData = eventitem;
// find event object in calendar
var eventsarr = $('#calendar').fullCalendar('clientEvents');
$.each(eventsarr, function(key, eventobj)
if(eventobj._id == eventitem.id)
console.log('merging events');
eventobj.start = eventitem.start;
eventobj.end = eventitem.end;
eventobj.title = eventitem.title;
$('#calendar').fullCalendar('updateEvent', eventobj);
);
// break each loop
return false;
);
if(!eventmerge)
// console.log('adding event id: '+eventcount);
eventData =
id: eventcount, // identifier
title: title,
start: start,
end: end,
color: '#00AA00',
editable: true,
eventDurationEditable: true,
;
// register event in array
allevents[eventcount] = eventData;
eventcount++;
$('#calendar').fullCalendar('renderEvent', eventData, true);
// console.log(start, end);
setTimePrice(eventData);
$('#calendar').fullCalendar('unselect');
,
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270929%2fhow-merge-events-in-fullcalendar-on-select-drag%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try it, hope it's fine for you.
select: function (start, end, jsEvent, view)
var diffmin = (new Date(end).getTime()/1000 - new Date(start).getTime()/1000)/60;
var title = diffmin+' min';
var eventData;
// some users click 1 slot, then the following, so we have 2 events each 30 min instead of 60 min
// merge both events into one
var eventmerge = false;
$.each(allevents, function( index, eventitem )
if(eventitem!==null && typeof eventitem != 'undefined')
// if start time of new event (2nd slot) is end time of existing event (1st slot)
if( moment(start).format('YYYY-MM-DD HH:mm') == moment(eventitem.end).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets end data of new merging event
eventitem.end = end;
// if end time of new event (1st slot) is start time of existing event (2nd slot)
else if( moment(end).format('YYYY-MM-DD HH:mm') == moment(eventitem.start).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets start data of new merging event
eventitem.start = start;
if(eventmerge)
// recalculate
var diffmin = (new Date(eventitem.end).getTime()/1000 - new Date(eventitem.start).getTime()/1000)/60;
eventitem.title = diffmin+' min';
// copy to eventData
eventData = eventitem;
// find event object in calendar
var eventsarr = $('#calendar').fullCalendar('clientEvents');
$.each(eventsarr, function(key, eventobj)
if(eventobj._id == eventitem.id)
console.log('merging events');
eventobj.start = eventitem.start;
eventobj.end = eventitem.end;
eventobj.title = eventitem.title;
$('#calendar').fullCalendar('updateEvent', eventobj);
);
// break each loop
return false;
);
if(!eventmerge)
// console.log('adding event id: '+eventcount);
eventData =
id: eventcount, // identifier
title: title,
start: start,
end: end,
color: '#00AA00',
editable: true,
eventDurationEditable: true,
;
// register event in array
allevents[eventcount] = eventData;
eventcount++;
$('#calendar').fullCalendar('renderEvent', eventData, true);
// console.log(start, end);
setTimePrice(eventData);
$('#calendar').fullCalendar('unselect');
,
add a comment |
Try it, hope it's fine for you.
select: function (start, end, jsEvent, view)
var diffmin = (new Date(end).getTime()/1000 - new Date(start).getTime()/1000)/60;
var title = diffmin+' min';
var eventData;
// some users click 1 slot, then the following, so we have 2 events each 30 min instead of 60 min
// merge both events into one
var eventmerge = false;
$.each(allevents, function( index, eventitem )
if(eventitem!==null && typeof eventitem != 'undefined')
// if start time of new event (2nd slot) is end time of existing event (1st slot)
if( moment(start).format('YYYY-MM-DD HH:mm') == moment(eventitem.end).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets end data of new merging event
eventitem.end = end;
// if end time of new event (1st slot) is start time of existing event (2nd slot)
else if( moment(end).format('YYYY-MM-DD HH:mm') == moment(eventitem.start).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets start data of new merging event
eventitem.start = start;
if(eventmerge)
// recalculate
var diffmin = (new Date(eventitem.end).getTime()/1000 - new Date(eventitem.start).getTime()/1000)/60;
eventitem.title = diffmin+' min';
// copy to eventData
eventData = eventitem;
// find event object in calendar
var eventsarr = $('#calendar').fullCalendar('clientEvents');
$.each(eventsarr, function(key, eventobj)
if(eventobj._id == eventitem.id)
console.log('merging events');
eventobj.start = eventitem.start;
eventobj.end = eventitem.end;
eventobj.title = eventitem.title;
$('#calendar').fullCalendar('updateEvent', eventobj);
);
// break each loop
return false;
);
if(!eventmerge)
// console.log('adding event id: '+eventcount);
eventData =
id: eventcount, // identifier
title: title,
start: start,
end: end,
color: '#00AA00',
editable: true,
eventDurationEditable: true,
;
// register event in array
allevents[eventcount] = eventData;
eventcount++;
$('#calendar').fullCalendar('renderEvent', eventData, true);
// console.log(start, end);
setTimePrice(eventData);
$('#calendar').fullCalendar('unselect');
,
add a comment |
Try it, hope it's fine for you.
select: function (start, end, jsEvent, view)
var diffmin = (new Date(end).getTime()/1000 - new Date(start).getTime()/1000)/60;
var title = diffmin+' min';
var eventData;
// some users click 1 slot, then the following, so we have 2 events each 30 min instead of 60 min
// merge both events into one
var eventmerge = false;
$.each(allevents, function( index, eventitem )
if(eventitem!==null && typeof eventitem != 'undefined')
// if start time of new event (2nd slot) is end time of existing event (1st slot)
if( moment(start).format('YYYY-MM-DD HH:mm') == moment(eventitem.end).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets end data of new merging event
eventitem.end = end;
// if end time of new event (1st slot) is start time of existing event (2nd slot)
else if( moment(end).format('YYYY-MM-DD HH:mm') == moment(eventitem.start).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets start data of new merging event
eventitem.start = start;
if(eventmerge)
// recalculate
var diffmin = (new Date(eventitem.end).getTime()/1000 - new Date(eventitem.start).getTime()/1000)/60;
eventitem.title = diffmin+' min';
// copy to eventData
eventData = eventitem;
// find event object in calendar
var eventsarr = $('#calendar').fullCalendar('clientEvents');
$.each(eventsarr, function(key, eventobj)
if(eventobj._id == eventitem.id)
console.log('merging events');
eventobj.start = eventitem.start;
eventobj.end = eventitem.end;
eventobj.title = eventitem.title;
$('#calendar').fullCalendar('updateEvent', eventobj);
);
// break each loop
return false;
);
if(!eventmerge)
// console.log('adding event id: '+eventcount);
eventData =
id: eventcount, // identifier
title: title,
start: start,
end: end,
color: '#00AA00',
editable: true,
eventDurationEditable: true,
;
// register event in array
allevents[eventcount] = eventData;
eventcount++;
$('#calendar').fullCalendar('renderEvent', eventData, true);
// console.log(start, end);
setTimePrice(eventData);
$('#calendar').fullCalendar('unselect');
,
Try it, hope it's fine for you.
select: function (start, end, jsEvent, view)
var diffmin = (new Date(end).getTime()/1000 - new Date(start).getTime()/1000)/60;
var title = diffmin+' min';
var eventData;
// some users click 1 slot, then the following, so we have 2 events each 30 min instead of 60 min
// merge both events into one
var eventmerge = false;
$.each(allevents, function( index, eventitem )
if(eventitem!==null && typeof eventitem != 'undefined')
// if start time of new event (2nd slot) is end time of existing event (1st slot)
if( moment(start).format('YYYY-MM-DD HH:mm') == moment(eventitem.end).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets end data of new merging event
eventitem.end = end;
// if end time of new event (1st slot) is start time of existing event (2nd slot)
else if( moment(end).format('YYYY-MM-DD HH:mm') == moment(eventitem.start).format('YYYY-MM-DD HH:mm') )
eventmerge = true;
// existing event gets start data of new merging event
eventitem.start = start;
if(eventmerge)
// recalculate
var diffmin = (new Date(eventitem.end).getTime()/1000 - new Date(eventitem.start).getTime()/1000)/60;
eventitem.title = diffmin+' min';
// copy to eventData
eventData = eventitem;
// find event object in calendar
var eventsarr = $('#calendar').fullCalendar('clientEvents');
$.each(eventsarr, function(key, eventobj)
if(eventobj._id == eventitem.id)
console.log('merging events');
eventobj.start = eventitem.start;
eventobj.end = eventitem.end;
eventobj.title = eventitem.title;
$('#calendar').fullCalendar('updateEvent', eventobj);
);
// break each loop
return false;
);
if(!eventmerge)
// console.log('adding event id: '+eventcount);
eventData =
id: eventcount, // identifier
title: title,
start: start,
end: end,
color: '#00AA00',
editable: true,
eventDurationEditable: true,
;
// register event in array
allevents[eventcount] = eventData;
eventcount++;
$('#calendar').fullCalendar('renderEvent', eventData, true);
// console.log(start, end);
setTimePrice(eventData);
$('#calendar').fullCalendar('unselect');
,
answered Dec 4 '18 at 12:01
Neeraj PrajapatiNeeraj Prajapati
242113
242113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270929%2fhow-merge-events-in-fullcalendar-on-select-drag%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"user can select few events in the table with select event"...that's not how the select event works - it's for selecting a period of time in which to create a new event. It does not enable you to select an existing event.
– ADyson
Nov 13 '18 at 9:43
You can possibly use "select" to do what you want, as long as the user starts by selecting an empty space. Then you can look at the selected time period, and check fullCalendar's existing event list to see if any events overlap it (by examining their start and end times). Then you can delete those events and create one single event to cover that time period. But if the user starts by clicking an existing event, this will trigger "eventClick" (for a short click) or start a drag operation (if they hold the button longer, and "editable" is true)
– ADyson
Nov 13 '18 at 9:46