Little bug with AutoPostBackOnFilter & CurrentFilterFunction

7 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 15 Jul 2013 Link to this post

    It seems that if you set, for example, in the declarative .aspx page CurrentFilterFunction="StartsWith" on some columns together with AutoPostBackOnFilter="true", something weird happens.
    The first time you insert a value and click "enter" (or tab or whatever to start the auto postback filtering) everything works as expected and the column is correctly filtered with a value that "StartWith" but at the same time alle the other columns are reset to "Contains", even if in the declarative code they all have CurrentFilterFunction="StartsWith" .


    EDIT: maybe this is intended such that after the first filtering happens all other columns are set to "NoFilter" regardless of the CurrentFilterFunction="StartsWith" but it's somehow counter intuitive from a coding standpoint. As far as the filter texbox is empty and the CurrentFilterFunction is implemented it should remain as the deafult-ready one I guess.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Jul 2013 Link to this post

    Hi,

    Try setting the DataType property of the Column to String.

    ASPX:
    <telerik:GridBoundColumn DataField="EmployeeID" AutoPostBackOnFilter="true" DataType="System.String" CurrentFilterFunction="StartsWith"></telerik:GridBoundColumn>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 17 Jul 2013 Link to this post

    Hi Princy, I saw many great answers from you in the forum! Thanks for this one.
    This is not a big issue is just an "usability" plus so it doesn't matter if we don't solve it. Just wondering if it was intended
    It seems I already have the System.String datatype set:

    <telerik:GridBoundColumn UniqueName="UserName" DataField="UserName" DataType="System.String"
    HeaderText="Nome utente" ColumnGroupName="Anagrafica" HtmlEncode="true" ShowFilterIcon="true"
    FilterImageToolTip="" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith"
    ConvertEmptyStringToNull="true" FilterControlWidth="70%" ItemStyle-CssClass="RadGridBatchEditInput">
    </
    telerik:GridBoundColumn>

    I'm doing the sorting and filtering server side in NeedDataSource event, but I just read FilterExpression there and pass it to my custom BLL object. So I don't do any tweaks to the Column.CurrentFilterFunction there... well really I do it but just for the date columns that way:
                                                    
    For Each filterColumn As Telerik.Web.UI.GridColumn In view.Columns
        ' Adjust date values
        If Not String.IsNullOrWhiteSpace(filterColumn.EvaluateFilterExpression()) Then
            Select Case filterColumn.ColumnType.ToString
                Case "GridDateTimeColumn"
                    Dim dateColumn As GridDateTimeColumn = CType(filterColumn, GridDateTimeColumn)
                    viewFilter = Replace(viewFilter, filterColumn.EvaluateFilterExpression(), FilterDateToDb(dateColumn, grid))
            End Select
        End If
    Next

    Inside my "FilterDateToDB" method I do adjust the CurrentFilterFunction. But I don't touch the string one.

    I didn't try on a clean simple grid with CurrentFilterFunction="StartsWith" and AutoPostBackOnFilter="true" on some GridBoundColumns, but I guess it's a design "issue".
  5. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 22 Jul 2013 Link to this post

    Hello,

    The experienced behavior is expected. When setting the AutoPostBackOnFilter property on a grid column the filter function used is Contains. However, I could ensure you I have contacted our dev team for further consideration if the behavior could be changed in order to handle cases like yours.

    Regards,
    Antonio Stoilkov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 22 Jul 2013 Link to this post

    Hallo Antonio, thank you for replying back.
    Really when I set 
    CurrentFilterFunction="StartsWith" and AutoPostBackOnFilter="true" on a column, the auto postback works as expected and pressing "enter" (or tab or wathever) triggers the filter that actually starts with the entered chars.
    The problem arise on the following filter in another column where I put CurrentFilterFunction="StartsWith" and AutoPostBackOnFilter="true" that for some reason get reset to "Contains".
    So it works indeed but only on first filtering action.

  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Jul 2013 Link to this post

    Hi ,

    Please try the following code snippet to keep the Filter function to "StartsWith".

    ASPX:
    <Columns>
        <telerik:GridBoundColumn UniqueName="ShipCountry" DataField="ShipCountry" HeaderText="ShipCountry"
            CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true" />
        <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity"
            AutoPostBackOnFilter="true" />
    </Columns>

    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
       {
           RadGrid1.Columns[1].CurrentFilterFunction = GridKnownFunction.StartsWith;//Setting currentfilter function for second column
           RadGrid1.Rebind();
       }

    Thanks,
    Princy
  8. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 22 Jul 2013 Link to this post

    Hallo Princy, this could surely work as a fix. I should check first if the filter box of the column is empty before setting the FilterFunction to the default value (StartsWith), otherwise you may have just made a filtered search on that column for some other function and when you open the menu you find it set to "StartsWith" (I hope it's clear what I mean).
    So the workaround is ok with a simple check to know if there is any actual filter value for that column.
    Something like this should go...

    Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
           If String.IsNullOrWhiteSpace(RadGrid1.Columns(1).CurrentFilterValue) Then
                RadGrid1.Columns(1).CurrentFilterFunction = GridKnownFunction.StartsWith 'Setting currentfilter function for second column
           End If
           RadGrid1.Rebind()
    End Sub


    If you want to adjust columns by column UniqueName try this

    Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
        For Each column As GridColumn In RadGrid1.Columns
            If column.UniqueName = "UserName" OrElse column.UniqueName = "FirstName" OrElse column.UniqueName = "LastName" OrElse column.UniqueName = "CoommunityRole" Then
                If String.IsNullOrWhiteSpace(column.CurrentFilterValue) Then
                    column.CurrentFilterFunction = GridKnownFunction.StartsWith
                End If
            End If
        Next
    End Sub


    Thank you for showing the path to follow 
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017