Radscheduler sorting by custom parameter

5 posts, 0 answers
  1. Phani
    Phani avatar
    19 posts
    Member since:
    Dec 2013

    Posted 11 Dec 2013 Link to this post

    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?

  2. Phani
    Phani avatar
    19 posts
    Member since:
    Dec 2013

    Posted 13 Dec 2013 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 16 Dec 2013 Link to this post

    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.
  5. Neeraj Isaac
    Neeraj Isaac avatar
    2 posts
    Member since:
    Jan 2010

    Posted 15 Sep 2014 Link to this post

    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
     






  6. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 17 Sep 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017