To Stanislav - add getEvents2(...) into dhtmlxscheduler.js ?

Hello Stanislav,

First great job :slight_smile:

I have a list of items (custom field - select list) and I have to prevent events overlapping according to each item of the list (if I have 7 items then at the same time I can have a maximum of 7 rendez-vous).

So to do the job, what do you think about adding this function (with another name) into dhtmlxscheduler.js ? I think that it could be interesting for other people (and maintenance is in your hands :wink:).

scheduler.getEventsToCheckConflict = function(id,start,end){ var result = []; for (var a in this._events){ var ev = this._events[a]; if (ev && (ev.id != id) && ((ev.start_date<=start && ev.end_date>=start) || (ev.start_date<=end && ev.end_date>=end) || (ev.start_date>=start && ev.end_date<=end))) result.push(ev); } return result; };
I use it into scheduler_include.html that way (ev.text is the key of a select - an element of a list of items):

scheduler.attachEvent("onEventSave",function(id, ev, is_new_event){ var evs = scheduler.getEventsToCheckConflict(id, ev.start_date, ev.end_date); evs.sort(function(a,b){ return (a.start_date > b.start_date ? 1 : -1); }); for (var i=0; i<evs.length; i++) { if(evs[i].text == ev.text) { // It's the same item -> don't save. return false; } } return true; })

Thanks
JMi

There is a scheduler_collision.js which allows to do nearly the same, you can use include it and use

scheduler.attachEvent("onEventCollision", function(ev, evs){ for (var i=0; i<evs.length; i++) { if(evs[i].text == ev.text && evs[i].id != ev.id) { return true; //collision } } return false; //not collision });

if you are using units or timeline view - above code is not necessary, as scheduler will know about different units|sections and will not count them as collision

Thank you, it runs.