How to Filter a RadGrid When the Enter Key is Pressed

The solution for this was not totally obvious to me when reading the RadGrid documentation, so I did a bit of forum searching and found the solution below:

Let’s say you’ve got a RadGrid on your page, and you’ve configured it already to allow for filtering by setting the AllowFilteringByColumn property to true as follows:

 <radG:RadGrid ID="rgDistricts" runat="server" PageSize="5" Skin="Default" AllowFilteringByColumn="true" AllowPaging="True" AllowSorting="True" GridLines="None" AutoGenerateColumns="False" OnDeleteCommand="DistrictDelete" OnItemCommand="ItemClick" OnNeedDataSource="District_NeedDataSource">

The code above will insert filter boxes and a filter menu into your grid which will allow users to enter a value and select a filter funtion to filter the grid. This works good except it requires that a user enter a value and then use the mouse to select how they want to filter on that value before the grid is affected.

It would be faster and a better user experience to allow users to enter a value and then hit the enter key and then have the grid filter. So to achieve this, you have to tell each of your bound columns that a. you want to auto post back on filter and b. what default filter funtion to use as follows:

<radG:GridBoundColumn DataField="Address" SortExpression="Address" HeaderText="Address" UniqueName="Address" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"> </radG:GridBoundColumn>

10 Responses to “How to Filter a RadGrid When the Enter Key is Pressed”

  1. Adi December 8, 2008 at 6:04 pm #

    Hi do you know if a dedicated host is required for telerik? Can telerik run on a shared hosting with no access to IIS?

  2. shereen December 8, 2008 at 6:06 pm #

    Hi Adi, my initial feeling is that Telerik does require IIS to run. Your best bet would be to contact telerik support. They are usually pretty quick to respond and very helpful.

  3. Pedro Alonso December 8, 2008 at 6:07 pm #

    Excellent post! Do you know if there is a way to remove the filter icon? Since we’re using the enter key to make the post back I found it useless to display the filter icon…

  4. shereen December 8, 2008 at 6:07 pm #

    Hi Pedro, I actually wanted to look into that, but haven’t had a chance yet. If i figure it out, i’ll post it on here as an update and send you a follow up email. Thanks.

  5. Michael December 8, 2008 at 6:08 pm #

    Nice tip.

  6. Mihai December 8, 2008 at 6:08 pm #

    I found someting on telerik and modified it to disable the button. protected void dgTableListing_PreRender(object sender, EventArgs e) { foreach (GridColumn col in dgTableListing.MasterTableView.RenderColumns) { if (col.UniqueName == “Name”) { foreach (GridFilteringItem filter in dgTableListing.MasterTableView.GetItems(GridItemType.FilteringItem)) { filter[“Nom”].Controls[1].Visible = false; } } } }

  7. shereen December 8, 2008 at 6:08 pm #

    excellent tip, thanks Mihai!

  8. Chanrith March 5, 2013 at 9:12 am #

    Thanks Shereen! Though this post is over 6 years old it managed to help me today.

  9. shereen March 5, 2013 at 1:10 pm #

    Awesome, totally makes my day to hear that!

  10. Vincent November 18, 2014 at 11:00 pm #

    For what it’s worth (yet another year later), the Enter key is a default handler for the Ajax filter presuming you set the properties AutoPostBack=”true”.

    Also to hide the FilterIcon, there is now an attribute ShowFilterIcon=”False” if you’d like to hide the filter icon without resorting to tweaking the PreRender method.

Leave a Reply