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

Force a Filter to be applied on Enter Key

4 Answers 393 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 09 Feb 2013, 01:27 PM
My client is concerned that his users aren't very technical and the Rad Grid column filtering is a bit overwhelming for many of them. He would like for the "Contains" filter to be applied when automatically when they type a phrase into the TextBox and hit "Enter".  Any ideas if and how I can do this?

Thanks

Steve

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Feb 2013, 02:31 PM
Hello,

Please try with below code snippet.

<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name" CurrentFilterFunction="Contains"
    AutoPostBackOnFilter="true" ShowFilterIcon="false">
  </telerik:GridBoundColumn>


Thanks,
Jayesh Goyani
0
Steven
Top achievements
Rank 1
answered on 13 Apr 2013, 11:04 AM
This worked fine when I was using PostBacks, but I'm revising my code to work with ClientSide web methods. How do I get the grid to fire the ClientSide OnCommand when the user hits the Enter key or clicks the filter button on the client side?  Or are there other event(s) I should be hooking to capture these actions?  Ideally, hitting enter or clicking the filter button should call my script to reload the grid.
0
Eyup
Telerik team
answered on 18 Apr 2013, 04:42 AM
Hi Steven,

In case you want to filter only on Enter key, you will need to disable the AutoPostBackOnFilter property of the column and attach an OnClick client side event to the corresponding input element of the generated filter control:
Copy Code
Copy Code
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem filterItem = e.Item as GridFilteringItem;
        TextBox textBox = filterItem["ShipName"].Controls[0] as TextBox;
        textBox.Attributes.Add("onkeypress", "fireFilterCommand('" +
            "ShipName" + "','" + "Contains" + "',this, event)");
    }
}
JavaScript:
Copy Code
Copy Code
function fireFilterCommand(uniqueName, filterFunction, inputElement, args) {
    if (args.keyCode == 13) {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        masterTable.filter(uniqueName, inputElement.value, filterFunction);
    }
}

I hope this will prove helpful. Please give it a try and let me know about the result.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Shubham
Top achievements
Rank 1
answered on 31 May 2017, 09:19 AM

Thank You,

Very Useful

 

Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Steven
Top achievements
Rank 1
Eyup
Telerik team
Shubham
Top achievements
Rank 1
Share this question
or