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

Change the default from Equal To

8 Answers 90 Views
Filter
This is a migrated thread and some comments may be shown as answers.
rik butcher
Top achievements
Rank 1
rik butcher asked on 03 Aug 2011, 01:54 PM
hey guys, i have a plain jane radFilter: how can i get the default when i choose this to display something other than, "Equal To" - .jpg is attached.
thanks
rik

<

 

 

telerik:RadFilter ID="RadFilter1" runat="server">

 

 

 

<FieldEditors>

 

 

 

<telerik:RadFilterTextFieldEditor FieldName="WORKORDERNUMBER" DisplayName="Work Order#" DataType="System.String" />

 

 

 

<telerik:RadFilterTextFieldEditor FieldName="TRACKINGNUMBER" DisplayName="Tracking#" DataType="System.String" />

 

 

 

</FieldEditors>

 

 

 

</telerik:RadFilter>

 

8 Answers, 1 is accepted

Sort by
0
rik butcher
Top achievements
Rank 1
answered on 03 Aug 2011, 02:11 PM
i tried using this from the OnItemCommand: but get the Object Reference not set to an instance of an Object when it get's to the "RecreateControl()" method.
any help would be appreciated.
thx
 rik

 

 

 

 

protected void WorkOrdersRadFilter_ItemCommand(object sender, RadFilterCommandEventArgs e)

 

{

 

 

if (e.CommandName == RadFilter.AddExpressionCommandName)

 

{

e.Canceled =

 

true;

 

 

 

RadFilterContainsFilterExpression item = new RadFilterContainsFilterExpression("StartsWith");

 

(e.ExpressionItem

 

as RadFilterGroupExpressionItem).Expression.AddExpression(item);

 

WorkOrdersRadFilter.RecreateControl();

}

}

0
rik butcher
Top achievements
Rank 1
answered on 03 Aug 2011, 02:23 PM
just to be clear, i want the right hand side of the control to simply default to "Starts With" or anything else but "Equal To" don't care about datatypes or anything like that, just be able to Default to "Starts With"
thx
rik
0
Genti
Telerik team
answered on 04 Aug 2011, 01:52 PM
Hello Rik Butcher,

I see that you are not defining the FilterExpression correctly in the item command event.
If you want to hava a StartsWith function by default that you need to have a RadFilterStartsWithFilterExpression object. Also, you need to pass as  parameter the FieldName and not the field function.
So, after making the corrections your ItemCommand event of the RadFilter should look like this:

protected void WorkOrdersRadFilter_ItemCommand(object sender, RadFilterCommandEventArgs e)
{
    if (e.CommandName == RadFilter.AddExpressionCommandName)
    {
        e.Canceled = true;
        RadFilterStartsWithFilterExpression item = new RadFilterStartsWithFilterExpression("WORKORDERNUMBER");
        (e.ExpressionItem as RadFilterGroupExpressionItem).Expression.AddExpression(item);
        WorkOrdersRadFilter.RecreateControl();
    }
}


Best wishes,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
rik butcher
Top achievements
Rank 1
answered on 04 Aug 2011, 01:59 PM
ahh, so for every field Name - if i want to change the default i have to do it for each one?
0
Genti
Telerik team
answered on 04 Aug 2011, 03:22 PM
Hi Rik Butcher,

When you hit the Add Filter button the filter won't know what FilterExpression to generate unless you specify it. Also, the filter does not now for which of the FieldNames to generate the filter, unless you specify it using code.

An extension that you can make to the previous solution is to handle the situation when the ChangeExpressionFieldName happens.
i.e
protected void RadFilter1_ItemCommand(object sender, RadFilterCommandEventArgs e)
{
    if (e.CommandName == RadFilter.AddExpressionCommandName )
    {
        e.Canceled = true;
        RadFilterStartsWithFilterExpression item = new RadFilterStartsWithFilterExpression("ShipAddress");
         
        (e.ExpressionItem as RadFilterGroupExpressionItem).Expression.AddExpression(item);
        RadFilter1.RecreateControl();
    }
    else if (e.CommandName == RadFilter.ChangeExpressionFieldNameCommandName)
    {
        e.Canceled = true;
        RadFilterStartsWithFilterExpression item = new RadFilterStartsWithFilterExpression(e.CommandArgument.ToString());
        //replace the current item with the new item that has the default filter set to StartsWith
        int i = e.ExpressionItem.OwnerGroup.Expression.Expressions.IndexOf((e.ExpressionItem).OwnerGroup.Expression.FindByFieldName((((RadFilterSingleExpressionItem)(e.EventSource)).Expression).FieldName));
        e.ExpressionItem.OwnerGroup.Expression.Expressions.RemoveAt(i);
        e.ExpressionItem.OwnerGroup.Expression.Expressions.Insert(i, item);
 
        RadFilter1.RecreateControl();
    }
}



Regards,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
rik butcher
Top achievements
Rank 1
answered on 04 Aug 2011, 03:26 PM
thanks so much for the help. i will give this a shot, it'll be a tremendous help to our program which has dozens of pages w/ telerik RadFilters.
thanks again
rik
0
rik butcher
Top achievements
Rank 1
answered on 08 Aug 2011, 01:47 PM
FYI - works great. BUT - ONE MORE QUESTION. can i use the command object or PreRender to set the cursor, so the user can just start typing if it's a text field rather than move the mouse and set the cursor?
 thanks again for all of your help
rik
0
Mira
Telerik team
answered on 11 Aug 2011, 04:05 PM
Hello Rik,

Unfortunately, the desired functionality is not supported.

However, you might use the following code in order to set the focus to the last rendered textbox:
protected void RadFilter1_PreRender(object sender, EventArgs e)
{
    var ctrl = ControlsOfType<ITextControl>(RadFilter1).Where(p => p.GetType() != typeof(LiteralControl));
    if (ctrl.Count() > 0)
        (ctrl.Last() as Control).Focus();
}
 
public IEnumerable<T> ControlsOfType<T>(Control parent) where T : class
{
    foreach (Control control in parent.Controls)
    {
        if (control is T)
        {
            yield return control as T;
            continue;
        }
 
        foreach (T descendant in ControlsOfType<T>(control))
        {
            yield return descendant;
        }
    }
}

I hope it helps.

Best wishes,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Filter
Asked by
rik butcher
Top achievements
Rank 1
Answers by
rik butcher
Top achievements
Rank 1
Genti
Telerik team
Mira
Telerik team
Share this question
or