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

Adding custom filter properties to default GridView column filter

4 Answers 410 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Veteran
Martin asked on 24 Jun 2020, 02:47 PM

I want to create custom filter properties for my column in the RadGridView, similar to the example given here: https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/excel-like-filtering#customizing-excel-like-filtering-popup

What I have is a column with bool values that are converted to icons. I want to create a column filter where I have custom provided names for the properties which represents the bool values. According to this: https://docs.telerik.com/devtools/wpf/controls/radgridview/filtering/how-to/howto-customize-the-default-field-filter-editor a plain TextBox will be shown for a bool column, but I would like to show a StringFilterEditor with my own values for true and false. I would prefer to do this without creating a custom template.

Is this possible?

Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 29 Jun 2020, 11:46 AM

Hello Martin,

The mentioned StringFilterEditor control is shown when RadGridView's FilteringMode is FilterRow. Do you use this setting? I am asking because that are two completely different modes and I need to be sure which one you are using.

It will be great if you can share more information about the desired result.

Regards,
Yoan
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Martin
Top achievements
Rank 1
Veteran
answered on 29 Jun 2020, 03:05 PM

This is how the column that I have is defined:

                <telerik:GridViewDataColumn
                    DataMemberBinding="{Binding ReminderPassed, Mode=OneWay, Converter={StaticResource BoolToColumnFilterTextConverter}}"
                    x:Name="ReminderIcon"
                    CellStyle="{StaticResource IncidentListTextEffects}"
                    Header=""
                    FilterMemberPath="ReminderPassed"
                    IsReadOnly="True"
                    IsVisible="{Binding IsTemplateList, Converter={StaticResource InvertBoolConverter}}"
                    SortMemberPath="RemindAtLocal">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock
                                Margin="2,0"
                                Padding="0"
                                FontFamily="{StaticResource TelerikWebUI}"
                                Text="{StaticResource GlyphWarning}">
                                <TextBlock.Visibility>
                                    <MultiBinding>
                                        <MultiBinding.Converter>
                                            <valueConverters:CompareDateTimeToVisibilityConverter />
                                        </MultiBinding.Converter>
                                        <Binding Mode="OneWay" Path="RemindAtLocal" />
                                        <Binding
                                            Mode="OneWay"
                                            Path="Now"
                                            Source="{StaticResource DateTimeNowTicker}" />
                                    </MultiBinding>
                                </TextBlock.Visibility>
                            </TextBlock>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

It is bound to a bool value which is converted to a string. This solved the problem of showing the StringFilterEditor. Now the problem is that the filter values are "True" and "False" instead of what the converter is returning (see the attached file for a visual of how it looks). 

And here is my converter: 

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace NTS.Client.Features.Incidents.ValueConverters
{
class BoolToColumnFilterTextConverter : IValueConverter
    {
        /// <summary>
        ///     This converter is used for the filtering of the ReminderIcon column in the incident list
        ///     It is needed to display the correct names for the checkboxes in the filter list
        /// </summary>
        /// <param name="values"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object obj, Type targetType, object parameter, CultureInfo culture)
        {

            bool reminderPassed = (bool)obj;

            if(obj == null || reminderPassed)
            {
                return "PÃ¥minnelsetid passerad";
            }
            else
            {
                return "PÃ¥minnelsetid inte passerad";
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

 

I want the strings returned by the converter to show up in the column filter. How do I do that?

Thanks :)

 

0
Martin
Top achievements
Rank 1
Veteran
answered on 01 Jul 2020, 08:19 AM
I got the answer to my question here: https://www.telerik.com/forums/creating-custom-column-filter-for-boolean-value-column#d_8KJa6OXUGhy1LbyXuF0Q
0
Yoan
Telerik team
answered on 01 Jul 2020, 03:24 PM

Hi Martin,

Thank you for the update. I am glad to hear this.

If you have further questions, do not hesitate to contact us again.

Regards,
Yoan
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Veteran
Answers by
Yoan
Telerik team
Martin
Top achievements
Rank 1
Veteran
Share this question
or