Add event count to day header

2 posts, 0 answers
  1. MGrassman
    MGrassman avatar
    92 posts
    Member since:
    Apr 2007

    Posted 10 Jan 2008 Link to this post

    We really don't use the time feature of the calendar but more of a general list of what is being shipped that day.  We can have over 20 or 30 lots in a day but I don't want each day in the month view to be 20 or 30 rows deep.  Is there a way to display like 5 days but show the count after the days like 1 (22 total) 2 (3 total) etc...

  2. T. Tsonev
    T. Tsonev avatar
    2791 posts

    Posted 11 Jan 2008 Link to this post

    Hi Michael,

    Unfortunately, this is not going to be easy, as RadScheduler does not support templates for the day numbers.
    We have to walk the control tree and apply the count labels manually as the appointments are being rendered.
    Here is the implementation that I have came up with:

    public partial class DefaultCS : Page 
        private Hashtable processedDateWraps = new Hashtable(); 
        protected void RadScheduler1_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e) 
            if (RadScheduler1.SelectedView == SchedulerViewType.MonthView) 
                Control dayWrap = GetDateWrap(e.Container); 
                if (!processedDateWraps.ContainsKey(dayWrap)) 
                    // Only do the count once per day cell. 
                    processedDateWraps.Add(dayWrap, null); 
                    // We will use the appointment start time to determine the date for the current cell. 
                    // Appointments that span multiple days are a special case. 
                    // They are rendered in parts and by using the part index, we can still calculate the correct day. 
                    // For example part 1 will rendered on the start date, part 2 on the start date + 1 day and so on. 
                    Control aptControl = GetAppointmentControl(e.Container); 
                    int partIndex = Convert.ToInt32(aptControl.ID.Split('_')[1]); 
                    DateTime aptStart = e.Appointment.Start.AddDays(partIndex); 
                    // Calculate the day start and end time and count the appointments in it. 
                    DateTime dayStart = RadScheduler1.UtcDayStart(aptStart); 
                    DateTime dayEnd = dayStart.AddDays(1); 
                    int appointmentsCount = RadScheduler1.Appointments.GetAppointmentsInRange(dayStart, dayEnd).Count; 
                    // Add a literal control with the count. 
                    string label = string.Format(" ({0} total)", appointmentsCount); 
                    dayWrap.Controls.Add(new LiteralControl(label)); 
        private Control GetDateWrap(Control aptContainer) 
            Control cell = GetParentByCssClass(aptContainer, "rsCell"); 
            return cell.Controls[0]; // rsDateWrap 
        private Control GetAppointmentControl(Control aptContainer) 
            Control aptWrap = GetParentByCssClass(aptContainer, "rsAptWrap"); 
            return aptWrap.Parent; 
        private Control GetParentByCssClass(Control container, string cssClass) 
            Control parent = container; 
            while (parent != Page) 
                WebControl candidate = parent as WebControl; 
                if (candidate != null
                    string[] allClassses = candidate.CssClass.Split(' '); 
                    if (Array.IndexOf(allClassses, cssClass) != -1) 
                        return candidate; 
                parent = parent.Parent; 
            return null

    Note that major changes to the rendering of the month view might break this code. However, we do not plan such in the foreseeable future.

    Kind regards,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top