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

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

3 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 16 Jun 2016, 10:44 PM

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

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 21 Jun 2016, 11:29 AM
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.
0
Jonathan
Top achievements
Rank 1
answered on 21 Jun 2016, 05:41 PM

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.

0
Maria Ilieva
Telerik team
answered on 24 Jun 2016, 01:56 PM
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.
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or