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

Resources and Grouping

4 Answers 138 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 22 Sep 2011, 05:56 PM
I have a custom appointment class and I need to group on one of the properties in the appointment... how do I do that? The property is called event and each appointment that has the same event value needs to be grouped together. I know that you can create resource collections and bind that to the ResourceTypesSource of the scheduleview... what I don't know is how does it know what resource the appointment belongs to or what appointment the resource belongs to?

The Event property of the custom appointment class holds an Event Id... I can populate a resource collection with events... but how could an appointment's event id connect with the id of the event within the collection? I can't specify the appointment's Resources property because it is read only... how does an appointment get Resources set???

4 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 27 Sep 2011, 02:25 PM
Hello Barry,

RadScheduleView currently supports only grouping by Resource, Date and TimeZone. The general principle is that the control needs to "know" what are all group names before the actual grouping has begun. In the case with the resources, the so called ResourceType contains all possible resources that an appointment can have. You could of course put any resource in the Resources collection of an appointment, but if the resources are not present in a type they are ignored. The ResourceTypes are added in the ResourceTypesSource collection on RadScheduleView.

Having that said, there is a hack (it has limitations) that can be used to simulate grouping by property by creating a custom appointment class, that will add/remove instances of the Resource type to its Resources collection depending on the value of the property. You also need to add a ResourceType that contains all resources that can appear in an appointment in the ResourceTypesSource collection of RadScheduleView.

Regards,
Valeri Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Barry
Top achievements
Rank 1
answered on 27 Sep 2011, 02:55 PM
Valeri,

What I ended up doing is overriding the Resources property of my custom appointment class... here is the code:

Public Property [Event] As String

Public Overrides ReadOnly Property Resources As Telerik.Windows.Controls.ResourceCollection
    Get
        Dim collection As New ResourceCollection
        Dim res As New Resource
        res.ResourceType = "Event"
        res.ResourceName = [Event]
        res.DisplayName = [Event]
        collection.Add(res)
        Return collection
    End Get
End Property

This adds the resources to the appointments, which have the value of the "Event" property. Then I use a sub-routine to get the ResourceTypes and fill a "ResourceTypes" collection:

Private Sub GetResourcesTypes()
    ResourceTypes.Clear()
    Dim t As New ResourceType
    t.DisplayName = "Event"
    t.Name = "Event"
    t.AllowMultipleSelection = False
    For Each p As ParsTask In TaskList
        If p.Resources(0).ResourceName <> "n/a" Then
            If Not t.Resources.Contains(p.Resources(0)) Then
                t.Resources.Add(p.Resources(0))
            End If
        End If
    Next
    ResourceTypes.Add(t)
End Sub

... which adds the types to a collection that I bind to the ResourceTypesSource in the xaml:

ResourceTypesSource="{Binding Source={StaticResource MainViewModel}, Path=ResourceTypes, Mode=TwoWay}"

And that seems to work. This way I can either clear the ResourceTypes collection and it won't group by resources or fill the collection to group by resources. I needed a way to group by the property "Event" and turn it on and off depending on the user's preference. I added a checkbox bound to a boolean value in my ViewModel that acts as the toggle and all seems to work just fine.

I'm guessing that you could add any of the properties from your custom appointment class (or multiple properties) and pick and choose which property to group by whenever you wanted to. I just need to group by one right now but that could come in handy later...

I'm guessing that is pretty much what you meant?? :)

Thanks!
0
Barry
Top achievements
Rank 1
answered on 27 Sep 2011, 03:07 PM
Valeri,

By the way, I still don't understand where the resources are supposed to come from. Are they supposed to be something that you can add just to group by? How would you normally add them if you didn't do it the way that I did?
0
Valeri Hristov
Telerik team
answered on 28 Sep 2011, 11:25 AM
Hi Barry,

The purpose of the resources is to easily add custom properties with known values to the appointments without the need to create custom appointment classes. For example, there are two ways to add a Locaton property to the Appointment class:
1) Create a new class, deriving from Appointment, add a Location property, customize the Edit Appointment dialog to include UI for setting the new property, add logic in the drag-drop behavior to handle the property, etc...
2) Define a ResourceType with Name="Location", add a few Resources inside it with Name="Room 1", "Room 2", etc. and the ScheduleView will do the rest automatically.

The so called "resources" could be thought of as custom properties of type Enum. You define the "enum" type by creating a ResourceType instance that contains all possible values of the "enum" (Resource instances). RadScheduleView will automatically use the provided resource types to construct its UI and will take them into account when dragging, grouping, etc. Adding Resource instances to the Appointment will effectively associate the appointment with the corresponding ResourceTypes. There are no limitations for the Appointment.Resources collection - it can contain any Resource instances, even if they are not present in the ResourceTypes of the corresponding ScheduleView control.

All the best,
Valeri Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ScheduleView
Asked by
Barry
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Barry
Top achievements
Rank 1
Share this question
or