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

Telerik Ajax Grid - Textbox value filter does NOT work with Double Quotes

2 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neelesh
Top achievements
Rank 1
Neelesh asked on 06 Apr 2016, 11:33 AM

Hi,

We are using Telerik Web UI for AJAX (version 2015.2.729.45). In grid we have data with double quotes (") and filter control is TextBox. Searching text with double quotes fails the search.

please see the attachment.

Code being used - Using the aspx standard script.

 <telerik:GridBoundColumn DataField="Name" HeaderText="Header" UniqueName="Name" FilterControlWidth="260px" AllowFiltering="true" ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" />

Kindly let us know for the solution.

Thanks.

Neelesh

2 Answers, 1 is accepted

Sort by
0
Roberto
Top achievements
Rank 1
answered on 06 Apr 2016, 01:19 PM

In RadGrid add EnableLinqExpressions="false"

On CodeBehind intercept RadGrid1_ItemCommand and add this changes:

Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
 
       If e.CommandName = RadGrid.FilterCommandName Then
           e.Canceled = True
           Dim filterPair As Pair = CType(e.CommandArgument, Pair)
           Dim ColumnName As String = filterPair.Second.ToString()
           Dim Column As GridColumn = RadGrid1.MasterTableView.GetColumn(ColumnName)
           Dim tbPattern As Object = Nothing
           Dim ControlValues As String = Nothing
           Dim GridFilterExpression As String = RadGrid1.MasterTableView.FilterExpression
           Dim CurrentFilterExpression As String = ""
           Dim NewFilterExpression As String = ""
 
           Dim ctrltype As String = CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString
 
           If CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString = "Telerik.Web.UI.RadMaskedTextBox" Then
               tbPattern = CType((CType(e.Item, GridFilteringItem))(ColumnName).Controls(0), RadMaskedTextBox)
               ControlValues = tbPattern.TextWithLiterals
           ElseIf CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString = "System.Web.UI.WebControls.TextBox" Then
               tbPattern = CType((CType(e.Item, GridFilteringItem))(ColumnName).Controls(0), TextBox)
               ControlValues = tbPattern.Text
           ElseIf CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString = "System.Web.UI.WebControls.CheckBox" Then
               tbPattern = CType((CType(e.Item, GridFilteringItem))(ColumnName).Controls(0), CheckBox)
               ControlValues = tbPattern.checked.ToString
           ElseIf CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString = "Telerik.Web.UI.RadDatePicker" Then
               tbPattern = CType((CType(e.Item, GridFilteringItem))(ColumnName).Controls(0), RadDatePicker)
               ControlValues = tbPattern.SelectedDate.ToString
           ElseIf CType(e.Item, GridFilteringItem)(ColumnName).Controls(0).GetType.ToString = "Telerik.Web.UI.RadNumericTextBox" Then
               tbPattern = CType((CType(e.Item, GridFilteringItem))(ColumnName).Controls(0), RadNumericTextBox)
               ControlValues = tbPattern.Value.ToString
           End If
 
           NewFilterExpression = MakeFilterExpression(filterPair.Second, filterPair.First.ToString(), ControlValues)
           Column.CurrentFilterFunction = RetGridKnownFunction(filterPair.First.ToString())
           If Column.CurrentFilterFunction = GridKnownFunction.NoFilter Then Column.CurrentFilterValue = ""
 
           Dim StartPos As Integer = InStr(GridFilterExpression, "([" + filterPair.Second + "]")
           Dim EndPos As Integer = InStr(StartPos + 1, GridFilterExpression, ")")
 
           If StartPos > 1 Then CurrentFilterExpression = "AND "
           If EndPos > 0 And GridFilterExpression.Contains(filterPair.Second) Then CurrentFilterExpression += Mid(GridFilterExpression, StartPos, EndPos + 2 - StartPos)
 
           If GridFilterExpression = "" Then
               RadGrid1.MasterTableView.FilterExpression = NewFilterExpression
           ElseIf GridFilterExpression = CurrentFilterExpression Then
               RadGrid1.MasterTableView.FilterExpression = Trim(Replace(RadGrid1.MasterTableView.FilterExpression, CurrentFilterExpression, NewFilterExpression))
           Else
               RadGrid1.MasterTableView.FilterExpression = Trim(Replace(RadGrid1.MasterTableView.FilterExpression, CurrentFilterExpression, "")) + IIf(Not String.IsNullOrEmpty(NewFilterExpression), " AND " + NewFilterExpression + "", "")
           End If
 
           If Left(RadGrid1.MasterTableView.FilterExpression, "3") = "AND" Then RadGrid1.MasterTableView.FilterExpression = Trim(Mid(RadGrid1.MasterTableView.FilterExpression, 5, Len(RadGrid1.MasterTableView.FilterExpression)))
           RadGrid1.Rebind()
 
       End If
   End Sub
 
   Function MakeFilterExpression(ColumnName As String, CurrentFilterFunction As String, Value As String) As String
 
       Dim Ret As String = ""
 
       Select Case CurrentFilterFunction
           Case "NoFilter"
               Ret = ""
           Case "Contains"
               Ret = "([" + ColumnName + "] Like '%" + Value + "%')"
           Case "DoesNotContain"
               Ret = "([" + ColumnName + "] Not Like '%" + Value + "%')"
           Case "StartsWith"
               Ret = "([" + ColumnName + "] Like '" + Value + "%')"
           Case "EndsWith"
               Ret = "([" + ColumnName + "] Like '%" + Value + "')"
           Case "EqualTo"
               Ret = "([" + ColumnName + "] = '" + Value + "')"
           Case "NotEqualTo"
               Ret = "([" + ColumnName + "] <> '" + Value + "')"
           Case "GreaterThan"
               Ret = "([" + ColumnName + "] > '" + Value + "')"
           Case "GreaterThanOrEqualTo"
               Ret = "([" + ColumnName + "] >= '" + Value + "')"
           Case "LessThan"
               Ret = "([" + ColumnName + "] < '" + Value + "')"
           Case "LessThanOrEqualTo"
               Ret = "([" + ColumnName + "] <= '" + Value + "')"
           Case "IsEmpty"
               Ret = "([" + ColumnName + "] = '')"
           Case "NotIsEmpty"
               Ret = "([" + ColumnName + "] <> '')"
           Case "IsNull"
               Ret = "([" + ColumnName + "] IS NULL)"
           Case "NotIsNull"
               Ret = "([" + ColumnName + "] NOT IS NULL)"
       End Select
 
       Return Ret
 
   End Function
 
   Function RetGridKnownFunction(FilterFunction As String) As GridKnownFunction
 
       Dim KFunction As GridKnownFunction
 
       Select Case FilterFunction
           Case "NoFilter"
               KFunction = GridKnownFunction.NoFilter
           Case "Contains"
               KFunction = GridKnownFunction.Contains
           Case "DoesNotContain"
               KFunction = GridKnownFunction.DoesNotContain
           Case "StartsWith"
               KFunction = GridKnownFunction.StartsWith
           Case "EndsWith"
               KFunction = GridKnownFunction.EndsWith
           Case "EqualTo"
               KFunction = GridKnownFunction.EqualTo
           Case "NotEqualTo"
               KFunction = GridKnownFunction.NotEqualTo
           Case "GreaterThan"
               KFunction = GridKnownFunction.GreaterThan
           Case "GreaterThanOrEqualTo"
               KFunction = GridKnownFunction.GreaterThanOrEqualTo
           Case "LessThan"
               KFunction = GridKnownFunction.LessThan
           Case "LessThanOrEqualTo"
               KFunction = GridKnownFunction.LessThanOrEqualTo
           Case "IsEmpty"
               KFunction = GridKnownFunction.IsEmpty
           Case "NotIsEmpty"
               KFunction = GridKnownFunction.NotIsEmpty
           Case "IsNull"
               KFunction = GridKnownFunction.IsNull
           Case "NotIsNull"
               KFunction = GridKnownFunction.NotIsNull
       End Select
 
       Return KFunction
 
   End Function

 

 

0
Eyup
Telerik team
answered on 11 Apr 2016, 10:32 AM
Hi Neelesh,

You can also check the following threads:
http://www.telerik.com/forums/filter-data-with-double-quotes
http://www.telerik.com/forums/radgrid-filter-with-and-and-or

Regards,
Eyup
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
Neelesh
Top achievements
Rank 1
Answers by
Roberto
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or