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

Duplicate Filter Entries

5 Answers 289 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 15 Nov 2011, 06:07 PM
Hello,

In my grid I display a number of values that are of type double.  When displaying these values in the table, I round the value to 2 decimal places using the GridViewDataColumn.DataFormatString property.  I also use the GridViewDataColumn.GroupHeaderFormatString to display full precision when grouping by these columns. 

However, the column filters still show duplicate entries in the list of column values, due to the rounding of the displayed values.  (See attached screenshot.)  I am wondering whether there is a way to display the values in the filter at higher precision (as I have done with grouping) so that it does not look like a list of duplicate values.  It sure would be nice if there were a property like GridViewDataColumn.FilterEntryFormatString!  Of course any other method would be helpful too! 

Any ideas as to what I might be able to do?

Thanks,
Mark


5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 17 Nov 2011, 11:18 AM
Hello Mark,

Actually this would not be so easy . In the default template for the filtering control we have a special converter to take care of applying string formatting and IValueConverter logic if such is present for the column. This is done for convenience in order to have a consistency between cells and distinct values in filter .

The solution : You need to redefine the template of the filtering control , removing  this converter.

*Since this is not an easy one  as an alternative I may suggest just to turn of the distinct values in the filter.

Greetings,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mark
Top achievements
Rank 1
answered on 22 Nov 2011, 05:34 PM
Hi Pavel,

Thanks for the response and suggestions. 

You mention "This is done for convenience in order to have a consistency between cells and distinct values in filter ."  However, as you can see in the screenshot, it is not presenting a list of distinct values in the filter.  Could this be a bug?  Should the filter perhaps run the cell values through the converter before creating the list of distinct values?

Thanks,
Mark.
0
Rossen Hristov
Telerik team
answered on 24 Nov 2011, 01:00 PM
Hello Mark,

Let me try to explain how the filtering control works. 

Imagine that you have defined a DataFormatString that rounds the number to the first digit after the decimal point. Now imagine that you have three raw double values -- 1.234, 1.235, 1.236.
 
Our data engine always works with the "raw" data, i.e. the actual double number. The filtering control will take a "raw" distinct value, i.e. the double 1.234, then check whether there is an IValueConverter defined on the column and if there is it will "pass" this raw value through it. Then it will also check whether there is a DataFormatString (like in your case) defined on the column and if there is it will apply it. What is produced after the application of the converter and string format, i.e."1.2" will be displayed in the distinct values list box. But this string "1.2" is for UI purposes only. When you check the "1.2" string in the distinct values list, it will be the double 1.234 that will be sent to the data engine. We generate LINQ expression in order to filter. So it will become something like this:

sourceCollection.Where(item => item.Amount == 1.234)

So, if you have the three distinct values 1.234, 1.235, 1.236 and if all of them produces the string "1.2" after being passed through the string format, then the distinct values list-box will show the string "1.2" three times. This is because the underlying original raw values are different, i.e. distinct and are equal to 1.234, 1.235, 1.236 respectively. You cannot have only a single list-box entry that reads "1.2". What should we filter on when the user clicks it? Which one should it be -- 1.234, 1.235, or 1.236? 

So, as my colleague suggested you can edit the XAML of the filtering control and change the binding of the CheckBox.Content. After you do this you will see the three distinct values 1.234, 1.235, and 1.236 in the list box instead of seeing the string "1.2" three times.

This is the part of the FilteringControl XAML that is responsible for this:

<ListBox.ItemTemplate>
    <DataTemplate>
        <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                  Content="{Binding ConvertedValue, Converter={StaticResource DistinctValueConverter}}"
                  VerticalContentAlignment="Center"
                  telerik:StyleManager.Theme="{StaticResource Theme}"/>
    </DataTemplate>
</ListBox.ItemTemplate>

Currently, you cannot do anything about it. But your request is reasonable.

That is why, I have added a new property called RawValue to the view model sitting behind the check-box. This property RawValue will return the raw value and you will be able to display it by changing the XAML like this:

<ListBox.ItemTemplate>
    <DataTemplate>
        <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                  Content="{Binding RawValue}"
                  VerticalContentAlignment="Center"
                  telerik:StyleManager.Theme="{StaticResource Theme}"/>
    </DataTemplate>
</ListBox.ItemTemplate>

You will be able to do that once we release our "Latest Internal Build" next Monday, which is when this new Value property will be made publicly available.

I hope that will help. Let me know if you need something else.

Greetings,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
ClausDC
Top achievements
Rank 1
Iron
Iron
answered on 25 Nov 2011, 10:15 AM
I have the same issue with date values.

My DataFormatString is "MMMM" which translates the date values to month names like "September", "October" and so on.

In the filter menu I have now dozens upon dozens of duplicate month name entries which frankly doesn't make any sense.

The user wants to filter by what he sees - not by some underlying internal values.

There should be a way to tell the filter menu that it should take the DataFormatString into account and only display distinct values. This would be very helpful.
0
Mark
Top achievements
Rank 1
answered on 29 Nov 2011, 05:42 PM
Hey Ross,

Thanks for the explanation and the implementation of RawValue - I will try it out as soon as I get a chance.

However, I am concerned that it does not really solve the issue.  Imagine that I use the RawValue feature as described below.  The user could then select 1.232 and 1.233 from the filter, but still see 1.23 in all the rows of the grid.  I think it is important (as ClausDC mentions) that the user is able to operate on the values he sees.

Thoughts?

Thanks,
Mark
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mark
Top achievements
Rank 1
Rossen Hristov
Telerik team
ClausDC
Top achievements
Rank 1
Iron
Iron
Share this question
or