it correcly add 1 minute to the end date but the problem remains… The start date does not correspond to the place where I dblclicked but to the start of the segment.
Eg: if I dblclick at 17.03 the start date will be 17.00 (instead of 17.03) the end date will be 17.01 (instead of 17.04) and on the scheduler a bar appear that spans from 17.00 to 17.05.
Everything works as expected during drag creation instead.
Hi,
As I know, this issue is already solved. My answer for others who also can struggle with this issue.
In timeline view the duration of event created by dblclick is equal the value of x_step property.
This config just add the same time step to the lightbox in Timeline, but doesn’t work for the duration of new added event.
As a rule I suggest the same way by redefining end_date when onEventCreated fires in such situation.
The start date does not correspond to the place where you dblclicked but to the start of the segment, because this event is called after creation new event and there you redefine duration = x_step. So when you save event by the lightbox, it will be updated on page.
To update it before opening the lightbox, add scheduler.updateEvent(id) :
testScheduler.attachEvent("onEventCreated", function(id, e) {
var event = testScheduler.getEvent(id);
event.end_date = testScheduler.date.add(event.start_date, 1, "minute");
});
Unfortunately it is still not a solution of the issue, because dblclick event in timeline doesn’t have info about the cursor position and set event.start_date == start_date of the cell.
The way I can provide you is to set ‘x_step: 1’, hide last 4 cells and their borders on the scale. As a result you will get smth like that docs.dhtmlx.com/scheduler/snippet/e0a655e6
In this case all new events will have correct dates correspond to the position of clicked place.
Also it’s possible do the same trick with timeline, not only with scale: docs.dhtmlx.com/scheduler/snippet/adae3fda
The second workaround is to get clicked position and update start_date according it
/* get the array of time slots*/
var scaleSlots = (testSchedulerElement.find('.dhx_scale_bar'));
/* get the percentage where the user clicked between the extremes of the time slot */
var percentage = Math.round(((e.pageX - $(scaleSlots.get(x_ind)).offset().left) / ($(scaleSlots.get(x_ind)).width()) * 100));
/* get the amount of step to be added to the default behaviour in order to set the event behind the double click spot */
var increase = Math.floor((currentSchedulerStep * percentage / 100));
/* update the event */
var event = testScheduler.getEvent(testScheduler.getState().lightbox_id);
event.type = ACTIVITY_GRAPHS_ADMINISTRATION_TYPE.BOLUS;
event.start_date = testScheduler.date.add(event.start_date, increase, "minute");
event.end_date = testScheduler.date.add(event.start_date, 1, "minute");
testScheduler.updateEvent(event.id);
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan