RadFilter numbers formatting

4 posts, 0 answers
  1. Elena
    Elena avatar
    11 posts
    Member since:
    Oct 2012

    Posted 29 Jan 2013 Link to this post

    Hi All,

    Is there a way to tell RadFilterNumericFieldEditor not to use thousands separator in its numeric editor? For example, I have columns that display Year or IDs. In the filter editor I want to see ‘2012’ and not ‘2,012’. For the column filters I did it with setting NumberFormat.GroupSeparator = "" on filteringItem, but cannot find a way to do it for RadFilter.

     
    Thanks.
    Elena.

  2. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 01 Feb 2013 Link to this post

    Hi Elena,

    You could achieve your scenario by overriding the Page PreRenderComplete method find all RadNumericTextBox controls and set their custom number format as shown below.
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
        IEnumerable<RadNumericTextBox> controls = FindControlsOfType<RadNumericTextBox>(RadFilter1);
        foreach (RadNumericTextBox textBox in controls)
        {
            textBox.NumberFormat.GroupSeparator = string.Empty;
        }
    }
     
    public static IEnumerable<T> FindControlsOfType<T>(Control parent)
                                                        where T : Control
    {
        foreach (Control child in parent.Controls)
        {
            if (child is T)
            {
                yield return (T)child;
            }
            else if (child.Controls.Count > 0)
            {
                foreach (T grandChild in FindControlsOfType<T>(child))
                {
                    yield return grandChild;
                }
            }
        }
    }

    All the best,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Elena
    Elena avatar
    11 posts
    Member since:
    Oct 2012

    Posted 01 Feb 2013 Link to this post

    Antonio,

    Thank you for the code. It was tricky to convert to VB so I used List instead as follows:
    Public Sub OnPreRenderComplete(ByVal e As EventArgs)
        Dim controls As New List(Of RadNumericTextBox)
        FindControlsOfType(Of RadNumericTextBox)(myRadFilter, controls)
     
        For Each textBox As RadNumericTextBox In controls
            For Each col In myRadGrid.MasterTableView.RenderColumns()
                If col.HeaderText = DirectCast(textBox.Parent.Controls(0), System.Web.UI.WebControls.HyperLink).Text Then
                    If (col.DataType.Name = "Int32" Or col.DataType.Name = "Int16") Then
                        textBox.NumberFormat.GroupSeparator = String.Empty
                    End If
                End If
            Next
        Next
    End Sub
     
    Public Shared Sub FindControlsOfType(Of T As Control)(parent As Control, ByRef myList As List(Of T))
        For Each child As Control In parent.Controls
            If TypeOf child Is T Then
                myList.Add(DirectCast(child, T))
            ElseIf child.Controls.Count > 0 Then
                FindControlsOfType(Of T)(child, myList)
            End If
        Next
    End Sub

    It seems to work, I just want to make sure that I did not miss anything.
    I want to apply the rule for a subset of Numeric TextBoxes based on the original column's DataType. Please let me know if there is an easier way to find the DataType of the original column.

    Thanks,
    Elena.
  5. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 06 Feb 2013 Link to this post

    Hi Elena,

    You could modify your code by checking the RadNumericTextBox NamingContainer which is RadFilterSingleExpressionItem and access its Expression.FieldName value and compare it to the column DataField.
    Dim fieldName As String = DirectCast(textBox.NamingContainer, Telerik.Web.UI.RadFilterSingleExpressionItem).Expression.FieldName
    If col.DataField = fieldName Then
        'your code logic
    End If


    Greetings,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top