I may just be missing something obvious, but I'm not having luck with this so far.
Thank you!
6 Answers, 1 is accepted
In order to achieve this, store the ColumnUniqueName in a session variable in ItemCommand event. Access the session variable in PreRender and then set the focus of filter textbox. Hope this helps.
C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e){ if (e.CommandName == RadGrid.FilterCommandName) { Pair filterPair = (Pair)e.CommandArgument; Session["filter"] = filterPair.Second.ToString();//storing ColumnUniqueName in session variable }}protected void RadGrid1_PreRender(object sender, EventArgs e){ int count = RadGrid1.Items.Count; if (count==0) { GridFilteringItem filteringItem = (GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0]; string ColumnUniqueName = Session["filter"].ToString(); TextBox box = filteringItem[ColumnUniqueName ].Controls[0] as TextBox; box.Focus(); }}Thanks,
Princy.
in Grid_ItemCommand:
HttpContext.Current.Items["FilterColumnName"] = filterPair.Second.ToString();in Grid_PreRender:
string columnUniqueName = HttpContext.Current.Items["FilterColumnName"].ToString();i had a little modification too so
it filters right away
put the focus on the last filter element
put the cursor at the end of the fitered text
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridFilteringItem filteringItem = (GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0];
string columnUniqueName = HttpContext.Current.Items["FilterColumnName"].ToString();
if (!string.IsNullOrEmpty(columnUniqueName))
{
TextBox box = filteringItem[columnUniqueName].Controls[0] as TextBox;
box.Attributes.Add("onFocus", "this.value=this.value"); // setting the cursor to the end of the text !!!
box.Focus();// focus the filter element
}
}
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
HttpContext.Current.Items["FilterColumnName"] = filterPair.Second.ToString();
}
}
<telerik:GridBoundColumn DataField="token" FilterControlAltText="Filter token column" HeaderText="token" SortExpression="token" UniqueName="token"
CurrentFilterFunction="Contains" AutoPostBackOnFilter="false" FilterDelay="1" ShowFilterIcon="false">
I am attaching a sample RadGrid web site to demonstrate an alternative solution for this case.
Regards,
Eyup
Telerik
