I’m working with a timeline scheduler with external drag and drop based on Jquery UI drag and drop.
When i drop an event it calls the scheduler method
// get action
scheduler.getActionData(event)
// create event object ... and add it
scheduler.addEvent(ev);
// But how to get start date ex: 22-12-2016 16:00 end date 22-12-2016 20:00??
But this only returns (Date) the object of the cursor-pointed date. Does anyone know how to use
jQuery draggable to get the start and enddate.
If you drag an external item, I’m not sure what do you mean by start and end points, as there is only one point - the point of drop.
If you drag and drop inside of the Scheduler, why not use a built in drag-to-create-event-behavior instead of jQuery UI actions?
I’m using a external div with events. The events could be dragged on the timeline. But after droping i only could get
the startdate where the mouse drops the event. I want also want to know the enddate.
I will try to explain in some more depth.
I have some external divs (events) that needs to be dropped on the scheduler timeline. Every event has a duration in hours.
When i grep an event for dragging, i calculate the hours. See code below
When the event is over the timeline i want to calculate the start/end date for storing into a database, how?
So for now i add an highlight div witch width is calculate by hours * cellWidth. (This is not working correctly, because the cell width is different after a couple of cells.)
If i could make this working properly, i want to try to calculate the start/end date by the highlighter start en end position if this is possible.
Scheduler won’t know the intended end date since it only knows mouse position which is a single point and interpreted as start date.
As I understand, in your handler you have task duration in hours so the end date can be easily calculated, e.g.:
[code]function(event, ui){
var hours = $helper.data(‘hours’);
var pos = scheduler.getActionData(event);
var start_date = pos.date;
var end_date = scheduler.date.add(start_date, hours*1, “hours”);
var section = pos.section;
…
scheduler.addEvent({
start_date: start_date,
end_date: end_date,
section_id: section,// section property as specified in ‘y_property’ of timeline
text: “new event”
});
}[/code]
Thx this was very helpfull, but i’ve some other problem to. In the scheduler (timeline) i am hidding weekends and hours.
So a week is without weekend, and a day starts from 00:00 till 07:00
The problem with the following code is, when i mouseover for example on friday: hour 05:00 it will add 10 hours
to the enddate. But this wil still return friday with a endtime of 05:00 + 10:00 = 15:00
But this needs to return monday 03:00
How could i use scheduler.date.add so that it knows the hidding hours and days??
scheduler.attachEvent("onMouseMove", function(id, event)
{
var hours = 10;
var pos = scheduler.getActionData(event);
var start_date = pos.date;
var end_date = scheduler.date.add(start_date, hours, "hour");
var section = pos.section;
console.log('hours: ' + hours);
console.log('start_date: ' + start_date);
console.log('end_date: ' + end_date);
console.log('section: ' + section);
});
// custom calc for enddate
var fix_enddate = function(date)
{
// get number of 15 minutes
// for exemple event_duration = 3 hours (3*60*60/900) = 12 pieces of 15 minutes
var nrOf15Min = ((event_duration * 60) * 60) / 900;
// counter
var i = 0;
while(i < nrOf15Min)
{
// increase end date
date.setMinutes(date.getMinutes() + time_interval);
// last hour on a day (days are from 00:00 - 08:00)
if(date.getHours() >= 8)
{
// add day
date.setDate(date.getDate() + 1);
// reset houres
date.setHours(0);
// if new date is weekend skip it
if(date.getDay() == 0 || date.getDay() == 6)
{
date.setDate(date.getDate() + 2);
}
}
i++;
}
return date;
};
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan