How To Wire A SharePoint List To A Telerik RadScheduler
Wiring a List of SPListItems to a Telerik RadScheduler is pretty easy. The important thing to remember when working with a RadScheduler is that it expects a list of Appointment objects, how you hydrate an Appointment object is pretty much up to you. Were it gets kinda weird is when you have the collection, the RadScheduler.Provider expects a SchedulerProviderBase super class. Either way it’s not too bad.
So let’s assume I am building the RadScheduler object in something like CreateChildControls like so:
- RadScheduler theScheduler = new RadScheduler();
- theScheduler.TimelineView.UserSelectable = true;
- theScheduler.OverflowBehavior = OverflowBehavior.Expand;
- theScheduler.SelectedView = SchedulerViewType.MonthView;
In the above I am missing the RadScheduler.Provider property, so gotta populate that. In this example, I am converting the SPList to a dataset, but you could iterate the items and return the values accordingly taking into account type casting. So I end up in a dataset format with something like this:
- tempCollection.AddRange(from DataRow row in masterTable.Rows
- select new Appointment
- {
- Start = DateTime.Parse(row[startFieldName].ToString()), End = DateTime.Parse(row[endFieldName].ToString()), ID = Guid.NewGuid(), Subject = StripTagsRegex(row[subjectFieldName].ToString()), RecurrenceState = state
- });
- public static string StripTagsRegex(string source)
- {
- return Regex.Replace(source, "", string.Empty);
- }
You could easily just do the SPListItems:
- tempCollection.AddRange(from SPListItem row in list.Items
- select new Appointment
- {
- Start = DateTime.Parse(row[startFieldName].ToString()), End = DateTime.Parse(row[endFieldName].ToString()), ID = Guid.NewGuid(), Subject = StripTagsRegex(row[subjectFieldName].ToString()), RecurrenceState = state
- });
Once you have the collection of Appointments, you have to make the SchedulerProviderBase superclass. This looks like this:
- public class ListSchedulerProvider : SchedulerProviderBase
- {
- private readonly List _listItemCollection;
- public ListSchedulerProvider(List collection)
- {
- _listItemCollection = new List();
- _listItemCollection = collection;
- }
- public override IEnumerable GetAppointments(RadScheduler owner)
- {
- return _listItemCollection;
- }
- public override IDictionary<ResourceType, IEnumerable<Resource>> GetResources(ISchedulerInfo schedulerInfo)
- {
- return new Dictionary<ResourceType, IEnumerable<Resource>>();
- }
- }
Then coordinate this class with scheduler Provider property:
- RadScheduler.Provider = new ListSchedulerProvider(Your Typed Appointment Collection);
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic
I am very interested in your post. because It is very helpful and useful for developers. Thanks for share this post.