Hi!
I have a radgrid that har AutoPostBackOnFilter="true" and CurrentFilterFunction="StartsWith".
Behavior observed:
1) The first time I enter a value and press enter, the filter expression is "(Country LIKE '1%')"
2) I then removed the value and presses enter again.
3) The filterexpression is now ""
4) I then enter a new value and press enter again.
5) Now the filterexpression is ""(Country LIKE '%2%')"
Why does the CurrentFilterFunction change when I press enter in a empty filter textbox?
Is there a way to stop this behavior?
I'm using Q1 2009 version.
Regards
Per
I have a radgrid that har AutoPostBackOnFilter="true" and CurrentFilterFunction="StartsWith".
Behavior observed:
1) The first time I enter a value and press enter, the filter expression is "(Country LIKE '1%')"
2) I then removed the value and presses enter again.
3) The filterexpression is now ""
4) I then enter a new value and press enter again.
5) Now the filterexpression is ""(Country LIKE '%2%')"
Why does the CurrentFilterFunction change when I press enter in a empty filter textbox?
Is there a way to stop this behavior?
I'm using Q1 2009 version.
Regards
Per
4 Answers, 1 is accepted
0
Accepted
Hi Per,
Indeed, the behavior is observed.
The reason for this is that the command is fired when you change the value in the textbox for the filter. It does not keep track of whether the value is empty, or perform any other validation. One possible option to work around this is to use client side script to check the value of the filter textbox, and cancel out the bubbling of the enter key press if there is no value.
I hope this suggestion helps.
Best wishes,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Indeed, the behavior is observed.
The reason for this is that the command is fired when you change the value in the textbox for the filter. It does not keep track of whether the value is empty, or perform any other validation. One possible option to work around this is to use client side script to check the value of the filter textbox, and cancel out the bubbling of the enter key press if there is no value.
I hope this suggestion helps.
Best wishes,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jessie
Top achievements
Rank 1
answered on 07 Dec 2009, 09:43 PM
Using client side script, how do I get the filter textbox to check the value and and then cancel the bubbling of the enter key press if there is no value?
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2009, 07:02 AM
Hello Jessie,
Here is an example that I implemented for a similar scenario, probably you could use the same logic:
aspx:
c#:
js:
Hope this helps..
Princy.
Here is an example that I implemented for a similar scenario, probably you could use the same logic:
aspx:
| <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product Name" AutoPostBackOnFilter="true" |
| CurrentFilterFunction="StartsWith" UniqueName="ColumnUniqueName"> |
| </telerik:GridBoundColumn> |
c#:
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridFilteringItem) |
| { |
| GridFilteringItem filterItem = (GridFilteringItem)e.Item; |
| TextBox txtbx = (TextBox)filterItem["ColumnUniqueName"].Controls[0]; |
| txtbx.Attributes.Add("onkeydown", "return txtkeypress('"+ txtbx.ClientID +"',event);"); |
| } |
| } |
js:
| function txtkeypress(txtbx) |
| { |
| var txtbx = document.getElementById(txtbx); |
| if(event.keyCode == 13) |
| { |
| if(txtbx.value == "") |
| { |
| return false; |
| } |
| else |
| { |
| return true; |
| } |
| } |
| } |
Hope this helps..
Princy.
0
Jessie
Top achievements
Rank 1
answered on 08 Dec 2009, 02:03 PM
Thanks, Princy. This is definitely what I was asking for. I ended up with a different solution for my situation. Basically, I wanted the Filter function to always be "StartsWith". I ended up using some codebehind in my RadGrid ItemCommand event handler like below:
| Protected Sub RadGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
| Select Case e.CommandName |
| Case RadGrid.FilterCommandName |
| CType(e.CommandArgument, Pair).First = "StartsWith" |
| Exit Select |
| End Sub |