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

The column filter is empty when I apply iValueConverter on DataMemberBinding

2 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jessica
Top achievements
Rank 1
Jessica asked on 02 Oct 2019, 08:36 PM

I need to pass multiple values into the i value converter but since multibinding isn't an option for DataMemberBinding I decided to pass the whole type into the converter as seen below: (I tried to only put the relevent code here)

                <telerik:GridViewDataColumn Header="{x:Static properties:Resources.Value}" DataMemberBinding="{Binding Converter={StaticResource myConverterSelector}}" TextAlignment="Center" HeaderTextAlignment="Center"  DataType="{x:Type sys:Double}" UniqueName="Value">

 

        public class MyConverterSelector : IValueConverter
    {
        public object Convert(object item, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            TabularTag tag = item as TabularTag;
            if (tag != null)
            {
                if (tag.Format == "Float" || tag.Format.Contains("REAL") || tag.Format == "")
                {

                    double parsedVal;
                    if (Double.TryParse(tag.Value.ToString(), out parsedVal))
                    {
                        return parsedVal.ToString("f3", CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    double parsedVal;
                    if (Double.TryParse(tag.Value.ToString(), out parsedVal))
                        return parsedVal.ToString("f0", CultureInfo.InvariantCulture);
                }
            }
            return null;
        }

        public object ConvertBack(object item, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

 

This works great on the cell data but the filter for this column ends up empty (I attached a snapshot of this) I tried using CellTemplate instead to edit the data but this doesn't affect the filter, which needs to match.

2 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 07 Oct 2019, 03:12 PM

Hi Jessica,

The behavior you described is expected and has been documented in the following help article. As stated there, the filtering (and sorting as well) are always performed on the raw data values and the IValueConverters are not used in this case. Even though you can "trick" the column into displaying the filtering icon and enabling the sorting by specifying the DataType property, this alone is not enough for these operations to function as expected.

You can also check this forum thread where this question has already been discussed.

My suggestion in your particular scenario would be to introduce a new property of your business objects to hold the value provided by the converter and directly bind your column to this property.

Regards,
Yoan
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
Jessica
Top achievements
Rank 1
answered on 07 Oct 2019, 03:26 PM

Thanks, I thought I might have to do that but it looked like it might end up being complicated with my code so I was hoping for another solution. I'll just do what you suggested though, thanks

 

Tags
GridView
Asked by
Jessica
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Jessica
Top achievements
Rank 1
Share this question
or