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

Adding a Filter expression on page load and pre-populating it

1 Answer 155 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 19 May 2010, 09:06 PM
Is there a way to create a series of Filter expression items, pre-populate them and display them when the grid is first loaded?

I saw another post that showed this example, but I cannot get it to display.

 

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();

 

RadFilter1.FieldEditors.Add(editor);

 

if (!IsPostBack)

 

{

editor.FieldName =

"MyColumnName";

 

editor.DataType =

typeof(int);

 

}

1 Answer, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 20 May 2010, 02:19 PM
Hi Richard,

Indeed the preceding code will add FieldEditor to the RadFilter control so that the field appears in the added expressions field name drop down.
However if you want to add a default filter expression, you can try extending the code as below:

protected void Page_Load(object sender, EventArgs e)
{
    RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
    RadFilter1.FieldEditors.Add(editor);
    if (!IsPostBack)
    {
        editor.FieldName = "ContactTitle";
        editor.DataType = typeof(string);
              
        RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("ContactTitle");           
        expr.Value = "Sales Representative";
        RadFilter1.RootGroup.Expressions.Add(expr);
    }
}

For your convenience I am attaching a runnable sample illustrating the suggested approach.

Regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Filter
Asked by
Richard
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Share this question
or