Problem concerning filters

Hey dhtmlxCommunity !

In my application, several users work with the scheduler. Each people can create events and define who is concerned by.

In my database, I’ve three tables for doing this : user, event_user & event.

An user can only see his events. I want this for the day, week and month view, it’s not a problem.
But I’ve created a timeline view and of course, I only have the user event.

I’ve my list with users, I just don’t know how load or filtered this.

You can load events from all users and filter necessary view.

Assuming that your event will have userId property, you can have filter as

scheduler.filter_day = scheduler.filter_week = scheduler.filter_month = function(ev_id, event){ if(event.userId == 123) return true; return false; };

where 123 - id of the current user

Thanks ! Sorry, I didn’t think that it was so simple. :stuck_out_tongue:

However, an event can concerned differents users. I extract my data with a SQL request, So I have it : event.idutil = ‘1,12,13’. I do this treatment: (idutil is same thing as userId for you).

scheduler.filter_day = scheduler.filter_week = scheduler.filter_month = function(ev_id, event){ if(event.idutil == current_user_id){ return true; } else{ if(event.idutil.indexOf(',') != -1){ alert(event.idutil.indexOf(',')); var reg = new RegExp("[,]+", "g"); var arrayIdUtil = event.idutil.split(reg); for (var i=0; i<arrayIdUtil.length; i++) { if(arrayIdUtil[i] == current_user_id) return true; } } } return false; };

It works but when I click to add an event, the scheduler is clear, and I have to click again to see the lightbox. I made some test and the problem come from indexOf() fonction, so I try the search() fonction but nothing change…

Anybody has an idea?

Most probably caused by the fact that new event will not have idutil property.
Change your code as

scheduler.filter_day = scheduler.filter_week = scheduler.filter_month = function(ev_id, event){ if(!event.idutil || (event.idutil == current_user_id)){ ...

Also add the next code on the page

scheduler.attachEvent("onEventCreated", function(id){
      scheduler.getEvent(id).idutil = current_user_id;
      return true;

which will assign current user id for newly created events