RadGridView - Custom Filtering Controls for a list of viewmodels

1 Answer 78 Views
GridView
Pablo
Top achievements
Rank 1
Pablo asked on 09 Jul 2024, 02:43 PM

Hi good morning, I need help with the design and how to implement a custom filter. If you can help me with a small example, I have been reading the "Custom Filtering Controls" documentation (https://docs.telerik.com/devtools/wpf/controls/radgridview/filtering/custom-filtering-controls) but I am having trouble implementing it for this case.

Currently I have a RadGridView, which shows a list of orders. One of the columns shows a list of icons:

public required List<IMvvmViewModel?> DesignStatusViewModels { get; set; }



Column:

<telerik:GridViewDataColumn IsReadOnly="True" HeaderCellStyle="{StaticResource DesignStatusCellStyle}">
    <telerik:GridViewDataColumn.Header>
        <TextBlock  
            Text="Design Status" 
            MinWidth="100"
            Width="Auto"
            TextAlignment="Center">
        </TextBlock>
    </telerik:GridViewDataColumn.Header>                    
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <ItemsControl ItemsSource="{Binding DesignStatusViewModels}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel 
                            Orientation="Horizontal"
                            HorizontalAlignment="Right"
                            TextElement.FontSize="12"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <ContentPresenter 
                            Grid.Row="0"
                            Content="{Binding }"
                            VerticalAlignment="Center"
                            ContentTemplateSelector="{StaticResource DesignStatusContentTemplateSelector}" 
                            Margin="2,0,2,0"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>




Each IMvvmViewModel has a bool, and a template, the template is responsible for showing the activated or not activated icon for each case, for example:

[DesignStatusTemplates(Template = typeof(DesignStatusRushOrderTemplate))]
publicpartialclassDesignStatusRushOrderViewModel : IMvvmViewModel
{
  publicbool IsRush { getset;}
}

[DesignStatusTemplates(Template = typeof(DesignStatusExternalOrderTemplate))]
publicpartialclassDesignStatusExternalOrderViewModel : IMvvmViewModel
{
publicbool IsExternal { get; set;}
}

What I need is to make a custom filter for this column, which can filter with a checkbox or whatever is easier, for example all orders that have DesignStatusRushOrderViewModel -> IsRush == true.

Thank you very much! Juan

  
Pablo
Top achievements
Rank 1
commented on 10 Jul 2024, 07:06 PM

Could someone please help me with the basic structure? Thank you so much!

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 12 Jul 2024, 02:46 PM | edited on 12 Jul 2024, 02:46 PM

Hello Pablo,

One way to achieve your requirement is to use a generic FilterDescriptor<T>. I have attached a very basic example showing how to filter the data using the generic filter descriptor and a custom IFilteringControl. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Pablo
Top achievements
Rank 1
commented on 17 Jul 2024, 03:20 AM

Martin thanks so much for the response, that worked like a charm!
Tags
GridView
Asked by
Pablo
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or