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

Custom filter date

3 Answers 124 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Anne
Top achievements
Rank 1
Anne asked on 18 Mar 2011, 11:28 AM
Hello,

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)
        MyBase.CopySettings(baseEditor)
        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)
        Get
            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
        Get
            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
            list.Add(Nothing)
        Else            
            list.Add(DateTime.Parse(combo.SelectedValue))
        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()))
  
        container.Controls.Add(combo)
    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 ?

Anne

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 24 Mar 2011, 08:52 AM
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,
Tsvetina
the Telerik team
0
&lt;&gt;&lt;
Top achievements
Rank 1
answered on 10 Jun 2011, 09:23 PM
Hey,

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.

Thanks
0
Anne
Top achievements
Rank 1
answered on 17 Jun 2011, 01:00 PM
Hi,

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.

combo.Items.Add(

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

 


Anne
Tags
Filter
Asked by
Anne
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
&lt;&gt;&lt;
Top achievements
Rank 1
Anne
Top achievements
Rank 1
Share this question
or