This project has moved. For the latest updates, please go here.


Built-in support for DataGridTemplateColumn



First, thanks for your great work on this project, attaching filtering behavior to existing grids is very handy.

I feel you should add built-in support for DataGridTemplateColumn though, as this column type is commonly used.

I managed to make it work in my project without too much trouble and without modifying the lib, but it's not the easiest way to set up, as I had to go and read the source code to figure out what to do.

I had to write a helper class:
public static class DataGridExtensionsHelper
    public static ResourceKey TemplateColumnFilterTemplateKey
        get { return new ComponentResourceKey(typeof(DataGridFilter), typeof(DataGridTemplateColumn)); }
and then I added the following resource:
<ControlTemplate x:Key="{x:Static screens:DataGridExtensionsHelper.TemplateColumnFilterTemplateKey}">
        <Control Style="{DynamicResource {x:Static dgx:DataGridFilter.IconStyleKey}}" />
        <TextBox Style="{DynamicResource {x:Static dgx:DataGridFilter.ColumnHeaderSearchTextBoxStyleKey}}"
                    Text="{Binding Path=Filter, UpdateSourceTrigger=PropertyChanged}" />
This makes filters work on DataGridTemplateColumn, and the filtering is done on the property defined by SortMemberPath.

Here are my proposals:
  • Add TemplateColumnFilterTemplateKey to the DataGridFilter class
  • Add a default ControlTemplate
  • Add an attached property DataGridFilterColumn.ValueToFilterBinding that would define what value to filter on. This way you'd be able to override the filtering behavior for any column type. It makes the most sense for template columns but it could still be useful for text columns. Fallback to SortMemberPath.


tomenglert wrote Jan 17, 2016 at 2:38 PM

Finally I got the time to add this.
However I decided against an extra filter binding for now, because sort & filter should align always anyhow, else you would get a very weird user experience...

LucasT wrote Jan 17, 2016 at 3:53 PM

Thanks, I'll update my code and see how it works out.

I suggested the filter binding for more flexibility as you can put literally anything inside a DataGridTemplateColumn - my reasoning was that it could prove useful, but I agree that is should be equal to SortMemberPath is most cases.
I also have to say I dislike SortMemberPath - it's not a binding and you don't get IntelliSense/refactoring support for it (even with ReSharper).

tomenglert wrote Jan 23, 2016 at 3:55 PM

I agree, but I think we have to live with this - deducing the SortMemberPath from a binding would not be possible, and specifying the SortMemberPath is kind of mandatory for template columns.