Filter problem on a GridDateTimeColumn

21 posts, 0 answers
  1. Tony
    Tony avatar
    22 posts
    Member since:
    Jun 2005

    Posted 27 Mar 2009 Link to this post

    Hi,

    I am using 2008 Q3 Controls with the latest hotfix applied (2008.3.1504.20).

    I have a RadGrid with two GridDateTimeColumns.  When you type a date into their filter textbox and either press enter or invoke the filter options drop down, the filter textbox simply clears itself and the value is ignored.

    I was experiencing the same behaviour with GridNumericColumns until I applied the hotfix over my previous dll (2008.3.1105.20).

    Here's my code:

    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" EnableEmbeddedSkins="false" Skin="Main" AllowFilteringByColumn="true">  
        <MasterTableView DataKeyNames="ContractID">  
            <Columns> 
                <telerik:GridButtonColumn ItemStyle-CssClass="editcolumn" CommandName="Edit" Text="Details/Edit" UniqueName="EditColumn" /> 
                <telerik:GridBoundColumn UniqueName="ContractID" FilterControlWidth="40px" HeaderText="Reference" DataField="ContractID" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridBoundColumn UniqueName="Address" FilterControlWidth="120px" HeaderText="Address" DataField="Address" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridDateTimeColumn DataType="System.DateTime" UniqueName="StartDate" FilterControlWidth="100px" HeaderText="Starts" DataField="StartDate" DataFormatString="{0:d}" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridDateTimeColumn DataType="System.DateTime" UniqueName="EndDate" FilterControlWidth="100px" HeaderText="Ends" DataField="EndDate" DataFormatString="{0:d}" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridNumericColumn UniqueName="Rent" FilterControlWidth="40px" HeaderText="Rent" DataField="Rent" DataFormatString="{0:C}" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridBoundColumn UniqueName="Frequency" FilterControlWidth="60px" HeaderText="Rent Frequency" DataField="Frequency" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
                <telerik:GridBoundColumn UniqueName="Status" FilterControlWidth="60px" HeaderText="Status" DataField="Status" AutoPostBackOnFilter="true" FilterListOptions="VaryByDataType" /> 
            </Columns> 
            <SortExpressions> 
                <telerik:GridSortExpression FieldName="ContractID" SortOrder="Descending" /> 
            </SortExpressions> 
        </MasterTableView> 
        <ClientSettings AllowColumnsReorder="true" Resizing-AllowColumnResize="true" /> 
    </telerik:RadGrid> 

    and I have the following VB in place to limit the filter options:

    Private Sub RadGrid1_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.Init  
        Dim menu As GridFilterMenu = RadGrid1.FilterMenu  
        Dim i As Integer = 0  
        While i < menu.Items.Count  
            If menu.Items(i).Text = "NoFilter" Or _  
                menu.Items(i).Text = "Contains" Or _  
                menu.Items(i).Text = "EqualTo" Or _  
                menu.Items(i).Text = "GreaterThan" Or _  
                menu.Items(i).Text = "LessThan" Then 
                i = i + 1  
            Else 
                menu.Items.RemoveAt(i)  
            End If 
        End While 
    End Sub 

    Am I fighting another bug in the dll or just missing something?
  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 27 Mar 2009 Link to this post

    Hello Tony-

    This scenario should work with the latest RadGrid bits. For a live example, check out this online demo:


    Enter a date in the datetime column, press Enter, and you should see the column filter. Let me know if you're seeing a different behavior with that demo. If everything works for you, you should be able to imitate the settings in that demo to get your code working. You may also want to take a look at the "CurrentFilterFunction" column property and see if that helps you, too.

    Hope that helps.
    -Todd
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 14 Apr 2009 Link to this post

    I am having the same problem and the example did not help me to solve it.

     <telerik:GridDateTimeColumn DataField="ActivityDate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date" SortExpression="ActivityDate" UniqueName="ActivityDate" 
                                        ColumnEditorID="GridDateTimeColumnEditorDates"  /> 




    In the grid I have this set: OnInit="RadGridFilter_Init"
    protected void RadGridFilter_Init(object sender, EventArgs e) 
        { 
            Misc.RadGridFilterOptions(sender, e); 
        } 

    public static void RadGridFilterOptions(object sender, EventArgs e) 
            { 
                RadGrid rg = (RadGrid)sender; 
                rg.EnableLinqExpressions = false
     
                rg.GroupingSettings.CaseSensitive = false
     
                //Setting the available filter options 
                GridFilterMenu menu = rg.FilterMenu; 
     
                for (int i = menu.Items.Count - 1; i >= 0; i--) 
                { 
                    if (menu.Items[i].Text == "NoFilter" 
                            || menu.Items[i].Text == "Contains" 
                            || menu.Items[i].Text == "EqualTo" 
                            || menu.Items[i].Text == "GreaterThan" 
                            || menu.Items[i].Text == "LessThan" 
                            || menu.Items[i].Text == "StartsWith"
                    { 
                        i--; 
                    } 
                    else 
                    { 
                        menu.Items.RemoveAt(i); 
                    } 
                } 
                 
     
                foreach (GridColumn column in rg.Columns) 
                { 
                    column.AutoPostBackOnFilter = true
                     
                    if (typeof(System.String) == column.DataType) 
                    { 
                        column.CurrentFilterFunction = GridKnownFunction.Contains; 
                    } 
                    else if (typeof(System.DateTime) == column.DataType) 
                    { 
                            column.CurrentFilterFunction = GridKnownFunction.EqualTo; 
                    } 
                    else  
                    { 
                        column.CurrentFilterFunction = GridKnownFunction.EqualTo; 
                    } 
                } 
            } 

    No matter what I do all columns filter fine except the date columns.  If you filter by the date column as your first filter it will work but if you have filtered any other column or are trying to filter the date column again the filter is set to "NoFilter" and with the autopostback enabled you cannot change the filter function or have it work correctly.

    All of the other columns work as expected so I am not sure what I am missing here.





  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 15 Apr 2009 Link to this post

    Hello sl6rp,

    Can you please verify that you are using the latest release 2009.1.402 of RadControls for ASP.NET AJAX in your project? Additionally, I noticed in your code that you set AutoPostBackOnFilter = true for each column in your grid. Hence you can remove the filter menu for your date time column by setting the ShowFilterIcon property for that column to false and use date input for it setting its PickerType property to None.

    Let me know whether this helps.

    Regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 15 Apr 2009 Link to this post

    I just downloaded and tried the latest release (2009.1.402).  It still exhibits the same behavior.  I want all of the columns to be filtered and to have the autopostback enabled.  It works for the first time you filter on the date but if you set the filter to No Filter and then try to filter again the postback fires before you can change the filter option from No Filter to GreaterThan, EqualTo, etc.

    It appears that the filter works fine as long as their is a filter applied but once you remove it (just from the date columns) you cannot filter again with out a fresh page load.
  7. Sreenivas
    Sreenivas avatar
    12 posts
    Member since:
    Dec 2007

    Posted 15 Apr 2009 Link to this post

    Hi,
    I am having same issue. Looks like its not only with GridDateTimeColumn, even with other columns also.
    Can some one send us the solution.

    I am using Q1 2009 version.

    Thanks
    Sreenivas.
  8. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 21 Apr 2009 Link to this post

    Hi guys,

    I have prepared a small sample which works as expected on my end. Can you try it and see if you can replicate the problem with it?

    Greetings,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 21 Apr 2009 Link to this post

    Your solution works if you completely ignore what we are trying to do.  I don't want to have to set every grid and every column's attributes.  That is why I use the on_Init to set these functions. The problem really lies in trying to limit the filter options.  If I don't remove items it works fine but if I use the following:

     for (int i = menu.Items.Count - 1; i >= 0; i--) 
                { 
                    if (menu.Items[i].Text == "NoFilter" 
                            || menu.Items[i].Text == "Contains" 
                            || menu.Items[i].Text == "EqualTo" 
                            || menu.Items[i].Text == "GreaterThan" 
                            || menu.Items[i].Text == "LessThan" 
                            || menu.Items[i].Text == "StartsWith"
                    { 
                        i--; 
                    } 
                    else 
                    { 
                        menu.Items.RemoveAt(i); 
                    } 
                } 

    the date columns get their filters set to no filter and because we have autopostback on filter enabled for every column you can't use the date column filter more than once before it gets set to NoFilter.



  10. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 24 Apr 2009 Link to this post

    Hi sl6rp,

    I added your code to the sample attached previously but still it seems to work as expected on my end. Could you try it and let me know if I am missing something important?

    Best wishes,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 24 Apr 2009 Link to this post

    Pavel,

    Thanks for taking a look at this.  I have downloaded and run the sample code you provided.  It still performs the same way mine does which is a problem.  I cannot get the date column (ShippedDate) to filter.  I can type in or select a date from the calendar and the page will flash quickly but not perform any filter.  All of the other columns work fine.  If you want, I can open a support ticket and attach a video of what I am talking about.  The OrderDate columns works but it does not use the datepicker in the filter.  Can you get the ShippedDate column to filter on multiple tries?

    Thanks

    -Brent
  12. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 27 Apr 2009 Link to this post

    Hello Brent,

    You are right and the filtering does not work as expected for this column. That can be fixed by setting its DataType property to "System.DateTime" in order for the CurrentFilterFunction to be set properly. Another approach is to use the ItemCreated event handler and call the RadGridFilterOptions function inside it.

    I am attaching the sample updated with the suggested changes. Try it out and let me know if you encounter any problems with it.

    Regards,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  13. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 27 Apr 2009 Link to this post

    Pavel,

    I tried the newest sample code you provided but it still does not work.  I had tried setting the DataType previously as well without success.  Did this code work on your end because I see the same behavior as before.

    Thanks

    -Brent
  14. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 28 Apr 2009 Link to this post

    Hello Brent,

    Unfortunately you are right again. The filtering works initially but it is reset after you select 'NoFilter' from the menu. The problem is that the Init event handler executes too early for the CurrentFilterFunction settings to be applied properly (they are reset after the filter command is executed). I can suggest you to use the PreRender handler to apply the settings. Please find attached the updated sample which works on my end and let me know if I am missing something else.

    Greetings,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  15. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 28 Apr 2009 Link to this post

    We are definitely getting closer.  The only problem I have found so far is if you have a checkbox column:

    <telerik:GridCheckBoxColumn DataField="Match" SortExpression="Match" UniqueName="Match" HeaderText="Match" DataType="System.Boolean" />

    Any time I include one of these columns in my grid the filtering stops working.

    -Brent



  16. Sreenivas
    Sreenivas avatar
    12 posts
    Member since:
    Dec 2007

    Posted 28 Apr 2009 Link to this post

    Hi,

    I am having similar issue. Sorry if I am not related to the same problem.

    I have a RadGrid with two columns, one with GridBoundColumn and another with GridDateTimeColumn.
    I also had enabled filter. On the same page I have Timer control for every 8 seconds I want to refresh the GRID.

    Problem here is, If I keep open the Calendar popup and If I don't close until 8 seconds, it throws error.
    Error is: Sys.InvalidOperationException: Component 'RadGrid1_gdtcSharedCalendar' was not found.

    Sample project is also attached. I have created a simple database table with two columns.

    Thanks in advance.

    Regards

    Sreenivas.

  17. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 29 Apr 2009 Link to this post

    Hi guys,

    Brent, if you add a CheckBoxColumn you should also ensure its CurrentFilterFunction is set to 'EqualTo':
    foreach (GridColumn column in rg.Columns) 
        if (typeof(System.String) == column.DataType) 
        { 
            column.CurrentFilterFunction = GridKnownFunction.Contains; 
        } 
        else if (typeof(System.DateTime) == column.DataType || typeof(System.Boolean) == column.DataType
        { 
            column.CurrentFilterFunction = GridKnownFunction.EqualTo; 
        } 
        else 
        { 
            column.CurrentFilterFunction = GridKnownFunction.GreaterThan; 
        } 


    Try it and let me know if that helps.

    Sreenivas, since your scenario seems to be a bit different, you may consider opening a support ticket and attaching to it a runnable sample which illustrates the problem. Thus we will get back to you right after we examine it.

    Best wishes,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  18. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 29 Apr 2009 Link to this post

    I had already done that before my last submission.  That does not work.

    -Brent
  19. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 30 Apr 2009 Link to this post

    Hi Brent,

    You are right again. You need to skip the CheckBoxColumn when setting the filter functions like this:
    foreach (GridColumn column in rg.Columns) 
        if (column is GridCheckBoxColumn) 
        { 
            continue
        } 
        if (typeof(System.String) == column.DataType) 
        { 
            column.CurrentFilterFunction = GridKnownFunction.Contains; 
        } 
        else if (typeof(System.DateTime) == column.DataType) 
        { 
            column.CurrentFilterFunction = GridKnownFunction.EqualTo; 
        } 
        else  
        { 
            column.CurrentFilterFunction = GridKnownFunction.GreaterThan; 
        } 

    Greetings,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  20. sl6rp
    sl6rp avatar
    55 posts
    Member since:
    Sep 2012

    Posted 01 May 2009 Link to this post

    I think that finally did it.

    Thanks for the help.

    -Brent
  21. Amit
    Amit avatar
    9 posts
    Member since:
    Aug 2010

    Posted 17 Dec 2010 Link to this post

    Hi

    I have GridDateTimeColumn with following code

    <telerik:GridDateTimeColumn DataField="AppTime1" HeaderText="App. Time" SortExpression="AppTime1"
                                                                            FilterListOptions="VaryByDataType" Resizable="true" AutoPostBackOnFilter="false"
                                                                            DataFormatString="{0:hh:mm tt}" PickerType="TimePicker" ShowSortIcon="true" FilterControlWidth="75%"
                                                                            DataType="System.DateTime">
                                                                        </telerik:GridDateTimeColumn>
    <telerik:GridDateTimeColumn DataField="AppTime1" HeaderText="App. Time" SortExpression="AppTime1"
                                                                            FilterListOptions="VaryByDataType" Resizable="true" AutoPostBackOnFilter="false"
                                                                            DataFormatString="{0:hh:mm tt}" PickerType="TimePicker" ShowSortIcon="true" FilterControlWidth="75%"
                                                                            DataType="System.DateTime">
                                                                        </telerik:GridDateTimeColumn>



     DataFormatString is hh,mm .Issue is that when i try to filter it with time chooser and filter it work for PM time where as it works sometime for AM time.
    I try to figure it out but can't find a solution.
    Please help


    Thanks And Regards
    Amit Kumar
  22. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 21 Dec 2010 Link to this post

    Hi Amit,

    I cannot reproduce this erroneous behavior. Please find attached a simple test page which works as expected on my end. Try it out and let me know how to alter it in order to replicate the behavior.

    Kind regards,
    Pavel
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017