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

Add event count to day header

1 Answer 113 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
MGrassman
Top achievements
Rank 2
MGrassman asked on 10 Jan 2008, 08:49 PM
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...

Thanks,

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 11 Jan 2008, 10:14 AM
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
Tags
Scheduler
Asked by
MGrassman
Top achievements
Rank 2
Answers by
T. Tsonev
Telerik team
Share this question
or