I'm attempting to filter a grid on a field that contains a file name and path. It appears that radgrid does not like filter strings that use the backslash (\) character. I have found a workaround (see code below) that intercepts the filter, escapes any backslash characters, and then aplies the filter. The code appears to work in that the filter is correctly applied. But for some reason, the text in the filter radtextbox gets cleared when the grid refreshes to apply the filter.
Is there a way to prevent the text box from being cleared?
Or alternately...is there a way to replace the text after the grid gets refreshed?
Below is the filter template, including the javascript codeblock, that applies the filter.
<telerik:GridTemplateColumn
UniqueName="Include"
DataField="Include"
SortExpression="Include"
HeaderText="Include"
HeaderStyle-Width="200px"
ShowFilterIcon="false"
FilterControlWidth="95%"
CurrentFilterFunction="Contains"
AutoPostBackOnFilter="true"
>
<EditItemTemplate>
<asp:textbox ID="txtInclude" runat="server" width="190px" Text='<%#Eval("Include")%>' />
<script type="text/javascript">
registeredElements.push('<%# Container.FindControl("txtInclude").ClientID %>');
</script>
</EditItemTemplate>
<ItemTemplate>
<div class="WordWrap" style="width:190px">
<asp:label ID="lblInclude" runat="server" CssClass="WordWrap" Text='<%#Eval("Include")%>' />
</div>
</ItemTemplate>
<FilterTemplate>
<telerik:RadTextBox ID="txtIncludeFileFilter" Width="100%" runat="server" >
<ClientEvents OnBlur="IncludeFileFilterChanged" />
</telerik:RadTextBox>
<telerik:RadScriptBlock ID="RadScriptBlock4" runat="server">
<script type="text/javascript">
function IncludeFileFilterChanged(sender, eventArgs) {
var filterValue = "";
var filterFunction = "NoFilter";
var s = sender.get_value();
if (s != "") {
filterValue = s.replace("\\", "\\\\");
var filterFunction = "Contains";
}
var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
tableView.filter("Include", filterValue, filterFunction);
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridTemplateColumn >