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

search text disappears...

3 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 01 Nov 2013, 11:26 PM
Hi,

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 >

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2013, 07:42 AM
Hi Raymond,

You can set the Text property of the RadTextBox in FilterTemplate to show the CurrentFilterValue. Please try the following code snippet.

ASPX:
<telerik:RadTextBox ID="txtIncludeFileFilter" Text='<%# ((GridItem)Container).OwnerTableView.GetColumn("Include").CurrentFilterValue %>'
    Width="100%" runat="server">
    <ClientEvents OnBlur="IncludeFileFilterChanged" />
</telerik:RadTextBox>

Thanks,
Princy
0
Raymond
Top achievements
Rank 1
answered on 04 Nov 2013, 04:18 PM
Hi,
I suspect the example you provided would have worked in c#.  I'm using vb and got it working using the following minor variation on your example:
<telerik:RadTextBox ID="txtIncludeFileFilter" Text='<%# Container.OwnerTableView.GetColumn("Include").CurrentFilterValue %>'
    Width="100%" runat="server">
    <ClientEvents OnBlur="IncludeFileFilterChanged" />
</telerik:RadTextBox>

Thanks...but I do have a final question on this.  Is it always necessary to bind the text box to the current filter?  I didn't notice that in any of the examples.  And it wasn't necessary when using a dropdown to select the filter value from a list.  Is it needed because I'm manually modifying the filter value?

Thanks again.

Ray
0
Princy
Top achievements
Rank 2
answered on 05 Nov 2013, 12:29 PM
Hi Raymond,

In order to persist the search text for filter in RadTextBox, its Text property should be bound to the CurrentFilterValue. Please have a look into this demo on  Grid - Filter Templates. It contains RadComboBox for filtering, the selected value is bound to the CurrentFilterValue. Please have a look in this forum, which says about the search text not persisting during postback.

Thanks,
Princy
Tags
Grid
Asked by
Raymond
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Raymond
Top achievements
Rank 1
Share this question
or