Change the default from Equal To

9 posts, 0 answers
  1. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 03 Aug 2011 Link to this post

    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>

     

  2. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 03 Aug 2011 Link to this post

    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();

    }

    }

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 03 Aug 2011 Link to this post

    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
  5. Genti
    Admin
    Genti avatar
    107 posts

    Posted 04 Aug 2011 Link to this post

    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.

  6. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 04 Aug 2011 Link to this post

    ahh, so for every field Name - if i want to change the default i have to do it for each one?
  7. Genti
    Admin
    Genti avatar
    107 posts

    Posted 04 Aug 2011 Link to this post

    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.

  8. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 04 Aug 2011 Link to this post

    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
  9. rik butcher
    rik butcher avatar
    106 posts
    Member since:
    Jul 2009

    Posted 08 Aug 2011 Link to this post

    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
  10. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 11 Aug 2011 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017