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

Row filter does not accept dot when filtering numeric column.

5 Answers 186 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 23 May 2019, 08:41 AM

Hi all,

we are using RadGridView version 2016.2.613.45 (.NET 4.5,  Visual studio 2017, C#) and are having issues with this functionality:

https://docs.telerik.com/devtools/wpf/controls/radgridview/filtering/how-to/howto-customize-the-default-field-filter-editor#filter-as-user-types

 

Basically, we have implemented a functionality to perform the filtering on every change(key press) in the filter bar.

However, we found a small issue(not to say a bug :) ).

When the filter mode is set to "RowFilter", and user is performing a filtering on numeric column, he is not able to type in the dot character(.).

The only way to get the dot in the filter is to type in the number and afterwards put the dot where you need it.

Example: trying to search for the number 556.32 you would need to type in the 55632 and afterwards place the dot where it needs to be.

This is only manifested when the filtering is set to trigger every time a user types. If we disable the functionality(remove the implementation), it works fine.

The implementation:

 

XAML:

<telerik:RadGridView ItemsSource="{Binding}" x:Name="radGridView" AutoGenerateColumns="False" >
            <telerik:RadGridView.Resources>
                <custom:ConditionalConvertor x:Key="converter"></custom:ConditionalConvertor>
            </telerik:RadGridView.Resources>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding SampleText}" Header="Sample Text"  >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataFormatString="{}{0:c0}" DataMemberBinding="{Binding SampleNumber,Converter={StaticResource converter}}" Header="Sample Number"  ></telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

 

In the code behind, we simply attach to the appropriate event:

this.radGridView.FieldFilterEditorCreated += WPFDataGrid_FieldFilterEditorCreated;

 

and in the "WPFDataGrid_FieldFilterEditorCreated" method we do:

 

private void WPFDataGrid_FieldFilterEditorCreated(object sender, EditorCreatedEventArgs e)
{
    var FilterEditor = e.Editor as Telerik.Windows.Controls.Filtering.Editors.StringFilterEditor;
    if (FilterEditor != null)
    {
        FilterEditor.MatchCaseVisibility = Visibility.Collapsed;
        FilterEditor.BorderBrush = new SolidColorBrush(Colors.Transparent);
        FilterEditor.Loaded += (s1, e1) =>
        {
            var textbox = e.Editor.ChildrenOfType<TextBox>().Single();
            textbox.TextChanged += (s2, e2) =>
            {
                textbox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            };
        };
    }
    else
    {
        if (e.Editor is TextBox)
        {
            var textbox = e.Editor as TextBox;
            textbox.TextChanged += (s2, e2) =>
            {
                textbox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            };
        }
    }
}

 

Any help would be appreciated.

Regards,

Igor

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 28 May 2019, 07:25 AM
Hi Igor,

Thank you very much for the provided code snippets.

I tried replicating the behavior you described in a small sample project, however, I'm able to input a dot symbol in the filter row. Could you please have a look at the attached project and let me know if I'm missing something of importance? As I omitted the ConditionalConvertor from the could you please try adding this to the project and let me know if it makes any difference?

Thank you in advance for your cooperation on the matter. I'm looking forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 28 May 2019, 07:55 AM

Hi Dilyan,

thank you for your reply.

I just made a small change in the project sample you sent and reproduced the issue.

The field "Number" in your "Player" class is declared as int, and filters work properly with this data type.

But, as soon as I refactored it to "decimal", the issue appeared.

So, here is the class implementation I used to reproduce the issue:

public class Player : ViewModelBase
    {
        private string name;
        private decimal number;
        private Position position;
        private string country;
 
        public string Name
        {
            get { return this.name; }
            set
            {
                if (value != this.name)
                {
                    this.name = value;
                    this.OnPropertyChanged("Name");
                }
            }
        }
 
        public decimal Number
        {
            get { return this.number; }
            set
            {
                if (value != this.number)
                {
                    this.number = value;
                    this.OnPropertyChanged("Number");
                }
            }
        }
 
        public Position Position
        {
            get { return this.position; }
            set
            {
                if (value != this.position)
                {
                    this.position = value;
                    this.OnPropertyChanged("Position");
                }
            }
        }
 
        public string Country
        {
            get { return this.country; }
            set
            {
                if (value != this.country)
                {
                    this.country = value;
                    this.OnPropertyChanged("Country");
                }
            }
        }
 
        public Player()
        {
 
        }
 
        public Player(string name, decimal number, Position position, string country)
        {
            this.name = name;
            this.number = number;
            this.position = position;
            this.country = country;
        }
 
        public override string ToString()
        {
            return this.Name;
        }
 
        public static ObservableCollection<Player> GetPlayers()
        {
            return new ObservableCollection<Player>(Club.GetClubs().SelectMany(c => c.Players));
        }

 

 

Best regards,

Igor

0
Dilyan Traykov
Telerik team
answered on 28 May 2019, 12:05 PM
Hi Igor,

Thank you for the update.

This behavior is expected as with the current implementation the input value is parsed on each keystroke. In this case, continuing the example you provided earlier, the value "556." is parsed to 556 each time you try to enter the dot symbol as this is simply how the TryParse method works in C#.

With this said, you can avoid this undesired behavior by updating the TextChanged event handler like so:

textbox.TextChanged += (s2, e2) =>
{
    if (!textbox.Text.EndsWith("."))
    {
        textbox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
    }
};

Please let me know if this works for you.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.

0
Igor
Top achievements
Rank 1
answered on 28 May 2019, 01:42 PM

Hi Dilyan,

 

thank you for the update. Yes, this indeed solved the issue.

However, it would be beneficial to have this behavior mentioned in the documentation, or mentioning it it in the how-to, to avoid the confusion.

 

Anyhow, case sorted. Thank you for your valuable time.

Best regards,

Igor

 

 

0
Dilyan Traykov
Telerik team
answered on 28 May 2019, 01:45 PM
Hi Igor,

I'm glad to hear that the issue is now resolved. I'd also like to thank you for your valuable feedback - we will consider updating the article with this information.

If I can further asssit you in any way, please let me know.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Igor
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Igor
Top achievements
Rank 1
Share this question
or