Welcome to the Xceed Community | Help
Community Search  
More Search Options

Custom Autofilter controls

Sort Posts: Previous Next
  •  07-31-2009, 12:29 PM Post no. 23094

    Custom Autofilter controls

    I'd like to implement my own (rather complex) autofilter control. I looked at the doc page for custom autofilter controls, but the functionality seems fairly limited. For instance, I'd like to add a pair of datepickers so that users can select date ranges from DateTime columns without needing to go through and check every date in their desired date range, and if possible, a list of weeks to select. For string columns, I'd like to give the user a textbox in which they can type a term by which to narrow down the filter values. Is there a way to use a custom AutoFilterControl subclass in place of the default one, or another way of doing what I'm looking to do?
  •  07-31-2009, 1:32 PM Post no. 23097 in reply to 23094

    Re: Custom Autofilter controls

    Have you considered providing custom distinct values rather than creating a custom auto-filter control?
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-31-2009, 2:07 PM Post no. 23098 in reply to 23097

    Re: Custom Autofilter controls

    I'm not exactly clear on how that would enable me to (for instance) add datepickers for date ranges. Could you go into a little more depth?

     

    Thank you.

  •  07-31-2009, 2:28 PM Post no. 23100 in reply to 23098

    Re: Custom Autofilter controls

    It wouldn't allow you to provide date picker controls, but it would allow you to create date ranges and any other custom filtering criteria you require. I don't think it would be possible to display date pickers even if you were to redo the AutoFilterControl.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-31-2009, 2:53 PM Post no. 23102 in reply to 23100

    Re: Custom Autofilter controls

    It would if I had access to the list of distinct values--I'd simply take the start and end date, iterate through the distinct items and add an AutoFilterValue for each item that fell within that range.

     

    Additionally, would it be possible to provide both custom distinct values AND the default list of distinct values? Because I think that is a requirement. 

  •  08-03-2009, 1:26 PM Post no. 23124 in reply to 23100

    Re: Custom Autofilter controls

    Is there any way for me to get the list of distinct values in code, and to replace the default AutofilterControl implementation with a custom one? If not, are there plans for this functionality in the future?
  •  08-12-2009, 1:25 PM Post no. 23306 in reply to 23094

    Re: Custom Autofilter controls

    For anyone looking to do this, I have figured out a (admittedly very hacky) way to do this. In your ControlTemplate for your AutoFilterControlStyle, place a hidden ListBox with the name "PART_DistinctValuesHost". Also place an instance of your custom AutoFilterControl, like so:

     

    <ControlTemplate TargetType="{x:Type DataGrid:AutoFilterControl}">

                                    <Border Background="White" BorderThickness="1">

                                        <Border.BorderBrush>

                                            <SolidColorBrush Color="Black" />

                                        </Border.BorderBrush>

                                        <Grid Background="White" Margin="10">

                                            <Grid.RowDefinitions>

                                                <RowDefinition Height="Auto"/>

                                            </Grid.RowDefinitions>


                                            <ListBox Name="PART_DistinctValuesHost" Visibility="Hidden" SelectionMode="Extended" />


                                            <CustomAutoFilterControls:MyCustomAutoFilterControl Grid.Row="0" Loaded="customAutofilter_Loaded"/>

                                        </Grid>

                                    </Border>

                                </ControlTemplate> 

     

     

    You custom Autofilter control must have a property of type ListBox (technically, it can be of type Selector, but as far as I know making it a ListBox type is the easiest way to enable multiple selected items). Hook into the custom autofilter control's Loaded event and assign the hidden ListBox to the custom autofilter's ListBox property (there's probably a way to do this with a binding, but I'm not good enough with bindings to get that working):

     

    private void customAutofilter_Loaded(object sender, RoutedEventArgs args)

    {

    MyCustomAutoFilterControl autoFilterControl = sender as MyCustomAutoFilterControl;

    if (autoFilterControl != null)

    {

    ListBox selector =

    (ListBox)((FrameworkElement)(autoFilterControl.Parent)).FindName("PART_DistinctValuesHost");

    //ItemsHost is the ListBox property

    autoFilterControl.ItemsHost = selector;

    }

    }

     

    In your custom autofilter control, whenever you need to access the list of distinct values, you can do it via ItemsHost.Items (or ItemsHost.SelectedItems to get the currently selected values). You can select distinct values by adding to ItemsHost.SelectedItems, clear selected values via ItemsHost.SelectedItems.Remove() or Clear(), etc.

     

    As I said: an extremely ugly hack, but if you need to give your users a more complex set of options for autofiltering, this seems to be the only way to do so right now. This also gives you the opportunity to present the user with different filtering options depending on the column's data type. For instance, you can give the user a textbox and filter out distinct values visible to the user based on the text entered when the column has strings, and you can also give the user a pair of datepickers to choose a date range if the column has DateTime objects. All you need to do is set each column's AutoFilterControlStyle to a different style depending on data type.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.