Remove Events by section_id

Hi.

When i remove a section, I want to find and remove all corresponding events from scheduler.
Now it seems (according to the API-Help) the only solution would be to get all events by
scheduler.getEvents(reallyEarlyDate, reallyLateDate);
and then using a loop to find and deleteEvent() all those with a given section_id individually.

That seems possible but clumsy. Is there a recommended way to do it?

Also: If I do it as above, the “onBeforeEventDelete”-Event would be fired.
I use the trash-symbol (event-delete) together with this event to delete the event from database, so in the above szenario all that sections events would be deleted, when all I want to archive is to keep that section and all its events from beeing displayed in scheduler (but still have them in database).

I hope I was clear enough. :slight_smile:

Regards,
Gerrit

Hello,

What view are you using? If it is units view then I can provide updated version where you can easily modify sections and events won’t be rendered if their section is not present.

Sorry, I didn’t quite get it.

As for solution:

  1. You can scheduler.clearAll() events and then load only the required ones. So ids of the sections should be passed in the call and server side should use them in the query. Requires editing server side code.
  2. You can loop through scheduler._events array and delete all events with specified section_id. After that re-render current view using scheduler.setCurrentView(scheduler.getState().date, scheduler.getState().mode). Though scheduler._event is not a public API.

Best regards,
Ilya

It is no big deal.
I just have to reload the scheduler everytime i remove a section.

But, just out of couriosity:
Can I remove events from scheduler without fireing the onBeforeDelete event?

You can’t block event itself, but if you are using dataprocessor for data saving, you can use

dp.ignore(function(){ scheduler.deleteEvent(id); });