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

RadFilter Events and Customization

13 Answers 431 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 17 Aug 2010, 03:34 PM

This is a great control, but I need some additional customization and events or properties of the event arguments.

I would like to be able to disable or hide the Group Operator button until more than one expression is added to reduce end user confusion.

As for the events, I need to be able to automatically add an expression when a new group is created, but I cannot find a way to grab the group that was just created using the ItemCommand event.

It would also be nice to be able to somehow bind an expression to a datasource or provide a valid list of options for users to select from.  This would be specifically useful where a field requires a code that is not understood by end users where we could give a description of that code instead of the code.

Are any of these currently possible and/or are they possibly future features?

13 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 20 Aug 2010, 12:37 PM
Hello Seth,

To your questions:
 - You can hide Add Group button in two ways
/using style/
<style type="text/css"
        li ul li div a.rfAddGr 
        
            display: none
        
</style>

/from code behind/
protected void RadFilter1_PreRender(object sender, EventArgs e) 
    
        foreach (var item in RadFilter1.RootGroupItem.ChildItems) 
        
            if (item is RadFilterGroupExpressionItem) 
            
                var group = (RadFilterGroupExpressionItem)item;                 
                ControlsOfType<LinkButton>(group, button => button.CommandName == RadFilter.AddGroupCommandName).First().Visible = false
            
        
    
    
    public IEnumerable<T> ControlsOfType<T>(Control parent, Predicate<T> where) where T : class
    
        foreach (Control control in parent.Controls) 
        
            if (control is T) 
            
                var result = control as T; 
                if (where(result)) 
                
                    yield return result; 
                    continue
                
            
    
            foreach (T descendant in ControlsOfType<T>(control, where)) 
            
                yield return descendant; 
            
        
    }

Both approaches above allows you to nest group items only in root group.

 - to achieve this you can cancel creation of the group item and build items you desire. For example:
protected void RadFilter_ItemCommand(object sender,  RadFilterCommandEventArgs args)
{
        if (args.CommandName == RadFilter.AddGroupCommandName)
    {
        args.Canceled = true;
        RadFilterGroupExpression group = new RadFilterGroupExpression();
        ((RadFilterGroupExpressionItem)args.ExpressionItem).Expression.AddExpression(group);
        RadFilterEqualToFilterExpression<string> expression = new RadFilterEqualToFilterExpression<string>(RadFilter1.FieldEditors[0].FieldName);
        group.AddExpression(expression);
        RadFilter1.RecreateControl();
    }
}

 - you can find attached example how to implement RadComboBox in RadFilter editor.

Best wishes,
Nikolay
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
0
Seth
Top achievements
Rank 1
answered on 24 Aug 2010, 05:03 PM
Thank you.

The group creation part worked well and I have yet to try the combobox example.

I am having trouble hiding the group boxes using code behind.  We use VB in our current project so maybe something got lost in my conversion.  Here is the code for VB.  Please let me know if I am missing something, it errors out at some point on the nested For Loop in the ControlsOfType function.

Public Sub FilterGroupsVisible(ByRef ActiveRadFilter As RadFilter)
    For Each oItem In ActiveRadFilter.RootGroupItem.ChildItems
        If TypeOf oItem Is RadFilterGroupExpressionItem Then
            Dim oGroup As RadFilterGroupExpressionItem = CType(oItem, RadFilterGroupExpressionItem)
            ControlsOfType(Of LinkButton)(oGroup, Function(button) button.CommandName = RadFilter.AddGroupCommandName).First().Visible = False
        End If
    Next
End Sub
Private Function ControlsOfType(Of T As Class)(ByVal parent As Control, ByVal where As Predicate(Of T)) As IEnumerable(Of T)
    For Each control As Control In parent.Controls
        If TypeOf control Is T Then
            Dim result = TryCast(control, T)
            If where(result) Then
                Return result
                Continue For
            End If
        End If
        For Each descendant As T In ControlsOfType(Of T)(control, where)
            Return descendant
        Next
    Next
End Function
0
Seth
Top achievements
Rank 1
answered on 26 Aug 2010, 09:44 PM

The example for the combo box works, but how can I apply it to a grid where the field already exists?  I tried to put the editor assignment in the FieldEditorCreated event of the Filter object but it doesn't seem to work. 

Protected Sub rfAdvancedDomestic_FieldEditorCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadFilterFieldEditorCreatedEventArgs) Handles rfAdvancedDomestic.FieldEditorCreated
    If e.Editor.FieldName = "StatusStage" Then
        Dim oEditor As New RadFilterDropDownEditor
        e.Editor = oEditor
        oEditor.DataTextField = "StatusGroupDesc"
        oEditor.DataValueField = "StatusGroupCode"
        oEditor.FieldName = "StatusStage"
        oEditor.DataType = GetType(String)
        oEditor.DisplayName = "Status Group"
        oEditor.DataSourceID = "sdsStatusGroups"
    End If
End Sub
0
Nikolay Rusev
Telerik team
answered on 27 Aug 2010, 08:12 AM
Hello Seth,

I suspect the conversion fails due to missing yield keyword in VB.NET. The algorithm is quite simple - iterates through Controls collection of given Control, checks whether current control is LinkButton with CommandName RadFilter.AddGroupCommandName and set visibility.

Regarding your second post: I am afraid that when using integration with RadGrid, RadFilter will automatically create editors per/grid column and they cannot be changed. You can programmatically populate RadFilter.FieldEditors collection and manually handle apply command and apply expressions on RadGrid.

Greetings,
Nikolay
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
0
Seth
Top achievements
Rank 1
answered on 27 Aug 2010, 08:59 PM

Can you provide a sample on how I can manually populate the FieldEditors for the RadFilter?  I attempted to do it but I get an error message when I try to add an expression:

System.ArgumentException: Parameter cannot be null or empty.
Parameter name: fieldName

I am populating the fieldName property as such:

 

 

 

Dim oRegFilter As New RadFilterTextFieldEditor

 

 

 

 

oRegFilter.FieldName = "B"

 

 

 

 

oRegFilter.DataType = GetType(String)

 

rfAdvancedDomestic.FieldEditors.Add(oRegFilter)

A sample would be nice as there is currently no documentation on server side code for this control that I could find on your site.

 

 

 

0
Iana Tsolova
Telerik team
answered on 02 Sep 2010, 09:27 AM
Hi Seth,

Can you check out the attached sample illustrating how you can add dynamica field editors and expression to RadFilter and see if this works for you. There is also shown how you can handle the ApplyExpression event.

Kind 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
0
Seth
Top achievements
Rank 1
answered on 17 Sep 2010, 08:39 PM
For those of you using VB that would want to accomplish some customization, here is how I did it:
    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        SetOperatorButtonVisible(_RadFilter.RootGroupItem)
    End Sub
'''
    Public Sub SetOperatorButtonVisible(ByRef GroupItem As RadFilterGroupExpressionItem)
        For Each oControl In GroupItem.Controls
            Dim oHyperLink As HyperLink = GetControlOfType(oControl, GetType(HyperLink))
            If oHyperLink IsNot Nothing Then
                If oHyperLink.Text.ToUpper = "AND" Then
                    oHyperLink.Visible = GroupItem.ChildItems.Count > 1
                End If
            End If
  
            Dim oLinkButton As LinkButton = GetControlOfType(oControl, GetType(LinkButton))
            If oLinkButton IsNot Nothing Then
                If oLinkButton.Text.ToUpper = "ADD EXPRESSION" Then
                    oLinkButton.Text = "Add Row"
                    oLinkButton.ToolTip = "Add Row"
                End If
            End If
        Next
  
        For Each oChildItem In GroupItem.ChildItems
            If TypeOf (oChildItem) Is RadFilterGroupExpressionItem Then
                Dim oGroup As RadFilterGroupExpressionItem = CType(oChildItem, RadFilterGroupExpressionItem)
                SetOperatorButtonVisible(oChildItem)
            End If
        Next
    End Sub
'''
    Public Function GetControlOfType(ByVal ParentControl As Control, ByVal TypeOfControl As Type) As Control
        Dim oLinkButton As Control = Nothing
  
        For Each oSubControl As Control In ParentControl.Controls
            If oLinkButton Is Nothing Then
                If oSubControl.GetType Is TypeOfControl Then
                    oLinkButton = oSubControl
                Else
                    oLinkButton = GetControlOfType(oSubControl, TypeOfControl)
                End If
            End If
        Next
  
        Return oLinkButton
    End Function
0
JB
Top achievements
Rank 2
answered on 21 Apr 2011, 08:07 PM
How can I disable the "Add Group" button in the RadFilter?

Is there a sample code available?

Thanks a bunch.


Joey
0
Iana Tsolova
Telerik team
answered on 26 Apr 2011, 01:17 PM
Hello JB,

One way to hide the "Add group" button is to add the below style to your page:
<style type="text/css">
.RadFilter_[SkinName] .rfAddGr 
{
    display:none;
}
</style>

Another approach is to use server-side code in the RadFilter PreRender event:
protected void RadFilter1_PreRender(object sender, EventArgs e)
{
    RadFilter1.RootGroupItem.Controls[2].Controls[1].Visible = false;
}


All the best,
Iana
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
JB
Top achievements
Rank 2
answered on 26 Apr 2011, 09:21 PM
The stylesheet works perfect.

Thanks!


Joey
0
July
Top achievements
Rank 2
answered on 15 Jul 2011, 04:29 PM
I need do it by this way

protected void RadFilter1_PreRender(object sender, EventArgs e)
{
    RadFilter1.RootGroupItem.Controls[2].Controls[1].Visible = false;
}

But doesnt work for me.
Said that this controls doesnt exist
0
Iana Tsolova
Telerik team
answered on 18 Jul 2011, 03:26 PM
Hi Julieta,

Try modifying it like this:
protected void RadFilter1_PreRender(object sender, EventArgs e)
{
    RadFilter1.RootGroupItem.Controls[0].Controls[2].Controls[1].Visible = false;
}


Regards,
Iana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Robin
Top achievements
Rank 1
answered on 29 Aug 2012, 02:16 PM
I was able to achieve the same thing using jQuery. 
$(".rfAddGr").css("display", "none");

For some reason I wasn't able to get the CSS working with the mixture of master pages and content pages. And when I tried to use the code behind option there was something in my code that caused the group to hide and then reappear.

I like this option best. It's cleaner, client side, and can be applied on a content page-by-content page basis.
Tags
Filter
Asked by
Seth
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Seth
Top achievements
Rank 1
Iana Tsolova
Telerik team
JB
Top achievements
Rank 2
July
Top achievements
Rank 2
Robin
Top achievements
Rank 1
Share this question
or