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

Radscheduler sorting by custom parameter

4 Answers 143 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Phani
Top achievements
Rank 1
Phani asked on 11 Dec 2013, 05:40 PM

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?

4 Answers, 1 is accepted

Sort by
0
Phani
Top achievements
Rank 1
answered on 13 Dec 2013, 07:44 PM

Class CustomAppointmentComparer

Implements IComparer(Of Telerik.Web.UI.Appointment)

Protected m_strField As String

Protected _sortDirection As SortDirection

Public Sub New(strField As String, sortDirection As SortDirection)

m_strField = strField

_sortDirection = sortDirection

End Sub

Public Function Compare(x As Telerik.Web.UI.Appointment, y As Telerik.Web.UI.Appointment) As Integer Implements IComparer(Of Telerik.Web.UI.Appointment).Compare

Select Case _sortDirection

Case SortDirection.Ascending

Return x.Attributes(m_strField) < y.Attributes(m_strField)

Case Else 'SortDirection.Descending

Return x.Attributes(m_strField) > y.Attributes(m_strField)

End Select

End Function





This is how I got it to work.

0
Plamen
Telerik team
answered on 16 Dec 2013, 11:59 AM
Hi,

Thank you for sharing the code that worked for your scenario.

Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Neeraj Isaac
Top achievements
Rank 1
answered on 15 Sep 2014, 12:36 PM
sorting is working fine up to 3 appointments , if it exceeds it is not sorting correctly .  
For ex : below is the output  from DB 


but it is not working in radscheduler as attached in this mail .

Thank you in advance.

Regards,
Neeraj.
















 StartDateTime
EnddateTime
Subject
 


14-09-2014
14-09-2014
7:00AM-7:30PM
 


14-09-2014
14-09-2014
7:30AM-11:30AM
 


14-09-2014
14-09-2014
8:00AM-3:00PM
 


14-09-2014
14-09-2014
8:45AM-12:45PM
 


14-09-2014
14-09-2014
11:30AM-3:30PM
 


14-09-2014
14-09-2014
3:00PM-11:00PM
 






0
Plamen
Telerik team
answered on 17 Sep 2014, 01:07 PM
Hi,

You can try the solution recommended in this thread.

Hope this will help you solve the issue.

Regards,
Plamen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Scheduler
Asked by
Phani
Top achievements
Rank 1
Answers by
Phani
Top achievements
Rank 1
Plamen
Telerik team
Neeraj Isaac
Top achievements
Rank 1
Share this question
or