Hello,
I have a radscheduler on my page. It is currently ordered by default, by start time of the appointment. I want the appointments to be sorted by a custom property "CompanyLocation". I followed this post but could not get the correct result. The post is this
http://www.telerik.com/community/forums/aspnet-ajax/scheduler/how-can-i-change-the-display-order-of-the-radscheduler-appointment-in-monthview.aspx
At the bottom you will see my comment there. I was wondering if that thread is closed. Basically I load a datatable from my stored procedure with 6 columns ID,Subject,Start,end,CompanyLocation. In mark up I have
CustomAttributeNames="CompanyLocation" EnableCustomAttributeEditing="true"
In my pageload I call a BindData function that populates and fills the datatable which I bind
radScheduler.DataSource = dt
radScheduler.DataBind()
Protected Overrides Sub OnInit(e As EventArgs)
MyBase.OnInit(e)
radScheduler.AppointmentComparer = New CustomAppointmentComparer("CompanyLocation", SortDirection.Descending)
End Sub
My CustomAppointmentComparer class is like this:
Class CustomAppointmentComparer
Implements IComparer
Private m_strField As String
Private _sortDirection As SortDirection
Sub New(strField As String, sortDirection As SortDirection)
m_strField = strField
_sortDirection = sortDirection
End Sub
Public Function Compare(first As Appointment, second As Appointment) As Integer
If first.Start < second.Start Then
Return -1
End If
If first.Start > second.Start Then
Return 1
End If
If first.[End] > second.[End] Then
Return -1
End If
Return [String].Compare(first.Attributes(m_strField), second.Attributes(m_strField))
End Function
Public Function Compare1(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
Dim apt1 As Appointment
Dim apt2 As Appointment
If GetType(Appointment).IsInstanceOfType(x) Then
apt1 = CType(x, Appointment)
Else
Throw New Exception("Casting failed...")
End If
If GetType(Appointment).IsInstanceOfType(y) Then
apt2 = CType(y, Appointment)
Else
Throw New Exception("Casting failed...")
End If
Select Case _sortDirection
Case SortDirection.Ascending
Return x.GetType.GetProperty(m_strField).GetValue(x, Nothing) < y.GetType.GetProperty(m_strField).GetValue(y, Nothing)
Case Else 'SortDirection.Descending
Return x.GetType.GetProperty(m_strField).GetValue(x, Nothing) > y.GetType.GetProperty(m_strField).GetValue(y, Nothing)
End Select
End Function
End Class
So what is that I am doing wrong?