Custom filter on one column that takes date values from itself and from another column to do a between like filter

4 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    2 posts
    Member since:
    Jun 2016

    Posted 16 Jun Link to this post

    What i want is to add a custom filter to one column that will takes the date from this column as first date and a date in another column as the second date to do a between like filter with these two dates.

    I added a custom filter with  FilterListOptions="VaryByDataTypeAllowCustom".

    then i added an handler like this (my second date is in "Col2") but this isn't working. What am i missing?:

    Protected Sub gvAbsence_ItemCommand(source As Object, e As GridCommandEventArgs) Handles gvAbsence.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                Dim filterPair As Pair = DirectCast(e.CommandArgument, Pair)
                If filterPair.First.ToString() = "Custom" Then
                    Dim colName As String = filterPair.Second.ToString()
                    If colName = "Col0" Then
                        Dim tbPattern As TextBox = TryCast(TryCast(e.Item, GridFilteringItem)(colName).Controls(0), TextBox)
                        Dim values As String() = tbPattern.Text.Split(" "c)
                        If values.Length = 1 Then
                            e.Canceled = True
                            Dim newFilter As String = "(([" + filterPair.Second + "] <='" + values(0) + "') AND ([" + "Col2" + "] >='" + values(0) + "'))"
                            If gvAbsence.MasterTableView.FilterExpression = "" Then
                                gvAbsence.MasterTableView.FilterExpression = newFilter
                            Else
                                gvAbsence.MasterTableView.FilterExpression = (Convert.ToString("((" + gvAbsence.MasterTableView.FilterExpression + ") AND (") & newFilter) + "))"
                            End If
                            gvAbsence.Rebind()
                        End If
                    End If
                End If
            End If
        End Sub

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Jun Link to this post

    Hi,

    You can implement filtering by date range as illustrated on this online demo:

    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx (see the second column in the second grid)

    Review the implementation under the source code tabs for more details.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonathan
    Jonathan avatar
    2 posts
    Member since:
    Jun 2016

    Posted 21 Jun Link to this post

    I dont think this is doing what i want to achieve.

    I want to put just one date in a filter (call it filterValue), and then, i want the grid to show only rows  that col0 is smaller than filtervalue and col2 is greater than filterValue

    because date in col0 is absence date and in col2 this is return to work date.

    And i want, when i put a date between absence date and return date, to see rows of people absent but not yet returned to work.

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Jun Link to this post

    Hello Jonathan,

    You can use the ItemCommand event handler to prevent the initial filtering and build the filtering expression manually according to your own requirements:
    http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

    Here is a similar sample:
    http://www.telerik.com/community/code-library/aspnet-ajax/grid/multi-selection-radcombobox-for-filtering-grid.aspx

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top