This is a migrated thread and some comments may be shown as answers.

Timeline Resource Grouping

11 Answers 137 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Timothy Kruszewski
Top achievements
Rank 1
Timothy Kruszewski asked on 30 Mar 2010, 06:20 PM
I want to know if it's possible to exclude resources when doing a group by if there are no appointments present for a particular resource.  Please see the attched file where resource user John Pieratt has no appointments scheduled for the week.  I do not want to see him when I group by users unless he has appointments for the given view. 

11 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 02 Apr 2010, 10:51 AM
Hello Timothy,

You can handle the RadScheduler OnDataBound event, enumerate the appointments and remove unused resources from the Resources collection.

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 02 Apr 2010, 08:24 PM
I'n not sure how to do this, could you provide a code example please?
0
Peter
Telerik team
answered on 06 Apr 2010, 12:11 PM
Hi Timothy,

Please, try the following approach:

protected void RadScheduler1_DataBound(object sender, EventArgs e)
   {      
       //Clear all resources of type 'user':
       foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User"))
       {
           RadScheduler1.Resources.Remove(res);
       }
       //Add resources of type 'user' that are in use for the visible range of RadScheduler:
       foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
       {
           RadScheduler1.Resources.Add(a.Resources.GetResourceByType("User"));
       }
   }


All the best,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 06 Apr 2010, 03:39 PM
Worked like a charm.  Thank you
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 16 Apr 2010, 05:05 PM

After doing more testing I've noticed a problem with the code example I was provided.  It appears that for evey entry by a particular user for the given date range it adds that user to the group by view.  So in the screen shot I provided Gabe has 9 entries for the week and he is showing up 9 times in the group by view.  Here is the code I'm using

protected void RadScheduler1_OnDataBound(object sender, EventArgs e)  
    {  
       //Clear all resources of type 'user':   
        foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User Name"))  
        {  
            RadScheduler1.Resources.Remove(res);  
        }   
       //Add resources of type 'user' that are in use for the visible range of RadScheduler:   
        foreach (Telerik.Web.UI.Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))  
        {  
            RadScheduler1.Resources.Add(a.Resources.GetResourceByType("User Name"));  
        }   
    } 
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 21 Apr 2010, 03:15 PM
Any word on this yet?  I've been waiting 5 days now..
0
Peter
Telerik team
answered on 22 Apr 2010, 11:56 AM
Hi Timothy,

Indeed, the code I sent you does not take into consideration that some resources could be added more than once. To prevent this, please modify the code as follows:

protected void RadScheduler1_DataBound(object sender, EventArgs e)
   {
       //Clear all resources of type 'user': 
       foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User"))
       {
           RadScheduler1.Resources.Remove(res);
       }
       //Add resources of type 'user' that are in use for the visible range of RadScheduler: 
       foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
       {
           if(a.Resources.GetResourceByType("User") != null){
               if(!RadScheduler1.Resources.Contains(a.Resources.GetResourceByType("User")))
                   RadScheduler1.Resources.Add(a.Resources.GetResourceByType("User"));     
           }       
       }
   }



Regards,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 25 May 2010, 11:15 PM
Thanks Peter, thats working great now but I discovered another hiccup with the code.  Lets say my user resource list contains 30 users but only 10 of them have scheduled items for the particular date range I'm looking at.  Those 10 users show up in the scheduler just fine but If I want to add someone who is not currently on the scheduler when I go into the form view to add them they are not in the user drop down list, only the 10 current users on the schedule are in the list.  So to sum it up is there a way to only display users with appointments in the scheduler but still have the ability to sidedly users who currently do not have appointments?

Thanks, Tim
0
Peter
Telerik team
answered on 31 May 2010, 09:39 AM

I see what you mean. I tried to workaround this 'hiccup' with code, but it led to complications. I wonder if it is plausible option for you to instruct users to use different view if they want to be able to choose from the entire list of resources. In terms of code you need just one extra check in the DataBound handler:

protected void RadScheduler1_DataBound(object sender, EventArgs e)
   {
       if (RadScheduler1.SelectedView == SchedulerViewType.TimelineView)
       {
           Session["ResUserList"] = RadScheduler1.Resources.GetResourcesByType("User");
           //Clear all resources of type 'user':
           foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User"))
           {
               RadScheduler1.Resources.Remove(res);
           }
           //Add resources of type 'user' that are in use for the visible range of RadScheduler:  
           foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
           {
               if (a.Resources.GetResourceByType("User") != null)
               {
                   if (!RadScheduler1.Resources.Contains(a.Resources.GetResourceByType("User")))
                       RadScheduler1.Resources.Add(a.Resources.GetResourceByType("User"));
               }
           
       }
   }

Let me know what you think of this approach.


Greetings,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 27 Jul 2010, 12:19 AM
That approach worked great but I need to be able to sort the resources users before they are added back to the list.  Can you provide a sample of how to do that please?

if (ddlUserView.SelectedValue == "1")
        {
            Session["ResUserList"] = RadScheduler1.Resources.GetResourcesByType("User Name");
            //Clear all resources of type 'user': 
            foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User Name"))
            {
                RadScheduler1.Resources.Remove(res);
            }
  
            //Add resources of type 'user' that are in use for the visible range of RadScheduler:   
            foreach (Telerik.Web.UI.Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
            {              
                if (a.Resources.GetResourceByType("User Name") != null)
                {
                    if (!RadScheduler1.Resources.Contains(a.Resources.GetResourceByType("User Name")))
                        RadScheduler1.Resources.Add(a.Resources.GetResourceByType("User Name"));
                }
            }
        }
0
Accepted
T. Tsonev
Telerik team
answered on 02 Aug 2010, 05:22 PM
Hello Timothy,

The resource collection doesn't allow for easy sorting, so you'll need to populate the resource in a List<Resource>, sort it and transfer the resources in the scheduler.

Something like this:

List<Resource> list = new List<Resource>();
foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
{
    Resource userName = a.Resources.GetResourceByType("User Name");
    if (userName != null && !list.Contains(userName))
    {
        list.Add(userName);
    }
}
 
list.Sort(delegate(Resource resA, Resource resB)
{
    return resA.Text.CompareTo(resB.Text);
});
 
RadScheduler1.Resources.AddRange(list);

I hope this helps.

Kind regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Scheduler
Asked by
Timothy Kruszewski
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Timothy Kruszewski
Top achievements
Rank 1
Peter
Telerik team
Share this question
or