Custom filter date

4 posts, 0 answers
  1. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 18 Mar 2011 Link to this post


    I build a class with Telerik Advices to custom filter date.

    My RadFilter bind a RadGrid.
    I can save filters in a sqlDataBase.

    When I choose a value in my custom combo filter date : no problem.
    I save it : no problem
    I load it the same day : no problem

    But if I load it the next day or after : I must select the value, again.
    It is very restriction for users which save their filters.
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports Telerik.Web.UI
    Imports System.Collections  
    'ACB - V1.0 - 07 septembre 2010
    ''' <summary>
    ''' filter on today or next days or last days''' </summary>
    ''' <remarks></remarks>
    Public Class DateFiltre
        Inherits RadFilterDataFieldEditor
        Protected Overrides Sub CopySettings(ByVal baseEditor As Telerik.Web.UI.RadFilterDataFieldEditor)
            Dim editor = TryCast(baseEditor, DateFiltre)
            If editor IsNot Nothing Then
                StartDate = editor.StartDate
             End If
        End Sub
        Public Property StartDate() As System.Nullable(Of DateTime)
                Return m_StartDate
            End Get
            Set(ByVal value As System.Nullable(Of DateTime))
                m_StartDate = value
            End Set
        End Property
        Private m_StartDate As System.Nullable(Of DateTime)
        Public Overrides Property DataType() As System.Type
                Return MyBase.DataType
            End Get
            Set(ByVal value As System.Type)
                MyBase.DataType = value
            End Set
        End Property
        Public Overrides Function ExtractValues() As System.Collections.ArrayList
            Dim list As New ArrayList()
            If combo.SelectedIndex = 0 Then
            End If
            Return list
        End Function
        Private combo As RadComboBox
        Public Overrides Sub InitializeEditor(ByVal container As System.Web.UI.Control)        
            Dim currentDate = If(StartDate, Date.Today)
            combo = New RadComboBox()
            combo.Items.Add(New RadComboBoxItem("select"))
            combo.Items.Add(New RadComboBoxItem("date+60", currentDate.AddDays(60).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+21", currentDate.AddDays(21).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+20", currentDate.AddDays(20).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+15", currentDate.AddDays(15).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+14", currentDate.AddDays(14).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+10", currentDate.AddDays(10).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+7", currentDate.AddDays(7).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+5", currentDate.AddDays(5).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+2", currentDate.AddDays(2).ToString()))
            combo.Items.Add(New RadComboBoxItem("date+1", currentDate.AddDays(1).ToString()))
            combo.Items.Add(New RadComboBoxItem("date", currentDate.ToString()))
            combo.Items.Add(New RadComboBoxItem("date-1", currentDate.AddDays(-1).ToString()))
            combo.Items.Add(New RadComboBoxItem("date-2", currentDate.AddDays(-2).ToString()))
            combo.Items.Add(New RadComboBoxItem("date-3", currentDate.AddDays(-3).ToString()))
        End Sub
        Public Overrides Sub SetEditorValues(ByVal values As System.Collections.ArrayList)
            If values(0) IsNot Nothing Then
                 combo.SelectedValue = values(0).ToString
            End If
        End Sub
    End Class

    Have you got an idea to find again my selected value ?

  2. Tsvetina
    Tsvetina avatar
    1861 posts

    Posted 24 Mar 2011 Link to this post

    Hello Anne,

    Since there is also a support thread started by you on the same problem, I would like to ask you to continue our communication on that matter there in order to avoid duplicate posts.

    If someone else is interested in the same functionality, as long as the LoadSettings() method of the RadFilter control is called on time and a correct string format is passed to it, the RadFilter control should be able to pass the editor value to the SetEditorValues() method where the combo will select the value in question.

    Best wishes,
    the Telerik team
  3. DevCraft R3 2016 release webinar banner
  4. &lt;&gt;&lt;
    &lt;&gt;&lt; avatar
    9 posts
    Member since:
    Apr 2011

    Posted 10 Jun 2011 Link to this post


    Quick question, does the above code perform a "Rolling Date" scenerio, where, if the fitler is saved (for example day-3), and I come back 3 days later, will it still select day-3 or will it now be at day-6 b/c it is storing the date in the saved filter?

    I'm assuming the latter, but just making sure.

    Edit: nevermind, found out the solution, just changed the extract values overide to fit my situation.

  5. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 17 Jun 2011 Link to this post


    If you come back 3 days later, you will be at day-6.
    The date is saved so now, I save the 'sql code' but the field of radfilter must be a string and not a datetime.


    New RadComboBoxItem("date+120", "CAST(CONVERT(varchar, GETDATE() + 120, 112) as datetime)"))


Back to Top