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

Little bug with AutoPostBackOnFilter & CurrentFilterFunction

6 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 15 Jul 2013, 12:12 PM
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.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Jul 2013, 11:05 AM
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.
0
Massimiliano
Top achievements
Rank 1
answered on 17 Jul 2013, 04:48 PM
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".
0
Antonio Stoilkov
Telerik team
answered on 22 Jul 2013, 08:45 AM
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.
0
Massimiliano
Top achievements
Rank 1
answered on 22 Jul 2013, 09:38 AM
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.

0
Princy
Top achievements
Rank 1
answered on 22 Jul 2013, 10:54 AM
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
0
Massimiliano
Top achievements
Rank 1
answered on 22 Jul 2013, 11:39 AM
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 
Tags
Grid
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Massimiliano
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or