Collision Detection Problem

I am creating events programmatically via javascript by calling scheduler.addEvent. I am able to create events fine this way. I’d like to be able to detect collisions on events created this way, but I’m not sure how. I have the collision code added and working as it does not allow me to create events via GUI that “collide”.

Can someone share the code I would need to use to detect a collision when adding events programmatically?

Basically, what I want is:
If an event that is going to be created will collide with an existing event, an alert will popup letting user know and new event will not be created.



Can anyone assist with my question?


Have you check ‘onEventCollision’ event?

Kind regards,

I did and do have code setup for the onCollision event. The code fires only when I create an overlapping event via drag-n-release (GUI). It does not fire when the event is created with the scheduler.addEvent code.

You can use addEventNow instead of add - it will trigger collision check.

Also, after event adding you can call something like

var collision = scheduler.callEvent(“onBeforeEventChanged”, [scheduler.getEvent(id)]);

which will return true if there is no collision, or false in case of collision

From what I understand, addEventNow triggers the lightbox. What if I wanted to just detect collisions without any user intervention?


var collision = scheduler.callEvent("onBeforeEventChanged", [scheduler.getEvent(id)]);

which will return true if there is no collision, or false in case of collision

returns true regardless of whether there’s any collision.

var collision = scheduler.callEvent(“onBeforeEventChanged”, [scheduler.getEvent(id)]);

This line do not check all events for collision, but only the one which id is used in the command.
Also, be sure that you have included ext/dhtmlxscheduler_collision.js


And in case you are using 3.5 beta version be sure to update it.

Kind regards,

Hi Stanislav,

Yes, I have include the ext/dhtmlxscheduler_collision.js
I use this code segment to add an event when a button is clicked.

		start_date: new Date(2012, 06, 28),
		end_date: new Date(2012, 06, 29),
		text: "Test Event",
		section_id: 1,
		id: "xxx",
	var collision = scheduler.callEvent("onBeforeEventChanged", [scheduler.getEvent("xxx")]);

However, I always get true regardless of whether it’s the first time I call this or if it’s the n-th time I call this.

Hi Ilya,

What do you mean by “be sure to update 3.5 beta”?

In case you are using 3.5 beta version then please download the latest version from the thread.

Kind regards,

Thanks Ilya, would 3.5 solve my problem?
I am still using 3.0 as I assume it’s the latest stable release?

No, if you are using 3.0 it’s alright as well.
I’ve tried the following:

scheduler.addEvent({ start_date: new Date(2012, 5, 28, 10), end_date: new Date(2012, 5, 28, 12), text: "Test Event", id: 569 }); scheduler.addEvent({ start_date: new Date(2012, 5, 28, 10), end_date: new Date(2012, 5, 28, 12), text: "Test Event", id: 570 }); var collision = scheduler.callEvent("onBeforeEventChanged", [scheduler.getEvent(570)]); alert(collision);
It correctly alerted me “false”.

Kind regards,

Hi Ilya,

That is very strange as the exact same code shows me true, regardless.

And based on the start date and end dates in your code segment, shouldn’t the correct response be that the collision is true since there is indeed a collision?


That’s indeed a collision and that’s why “onBeforeEventChanged” returned “false”. If everything would be alright = no collision it would return “true”.

Do you have “onEventCollision” set up with your own handler?

Kind regards,

I see. Thanks for the explanation!

Yes, I have setup an “onEventCollision” handler.
However, I still get a true value even when I’ve commented out the “onEventCollision” handler.

Is there anything else I can try?


Make sure to clear cache.
Also can you try the same code in the samples\03_extensions\15_collision.html in the original package?

Kind regards,


I tried with 2 different browsers, same issue. One of the browser has never ran the page before, so I don’t think it’s an issue with the cache.

I tried running samples\03_extensions\15_collision.html by itself and then adding the code segment to the page. And it still gives me a true.

The same code correctly detects collision for version 3.0 locally.
If you are using 3.0 and sample still occurs - please provide any kind of sample or demo link where issue can be reconstructed.