Hello,I'm using the XamDataGrid with DataSource containing a list of comma-separated strings. By default the filter row dropdown includes all items presented in grid. But in this case I would like to bind the filter dropdown to other property of viewmodel containing just the values which are presented in the grid as strings. Is there a way to do this? For better understanding I made a screenshot of how the dropdown looks currently:
What I want is that the dropdown contains each item (F01, F02 etc.) only once.Thanks in advance and kind regards,Daniel
Hi Daniel,
You can handle the RecordFilterDropDownOpening event in the XamDataGrid. Inside the event arguments you have access to the drop down items and can modify or remove them, or you can add your own as well.
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v14.2~Infragistics.Windows.DataPresenter.DataPresenterBase~RecordFilterDropDownOpening_EV.html
This gives you complete control over what is displayed inside the dropdown.
Hi Rob,I've tried that and it's not an option for me: I only have about 180 items in the grid and if I work with this event and try to delete existing filter items first and then fill the items I need its takes the dropdown about 30 seconds to open. Even if I'm not deleting existing items and just add 100 more it takes about 15 seconds which is incredibly slow. Do you have any other ideas? I think there has to be some way to change the data source for the filter drop down.Regards,Daniel
The reason it takes so long is because of all the collection changed notifications that are occurring when you remove / add that many items. Luckily, the e.DropDownItems collection is actually an ObservableCollectionExtended<T> object. This means you can suspend notifications until after you finished updating the list. In my tests this was considerably faster versus the normal way.
Just cast e.DropDownItems to an ObservableCollectionExtended<FilterDropDown> and then call BeginUpdate. After BeginUpdate, you can clear and add the items that you need. Once finished, call EndUpdate and the collection will fire a single collection changed notification to let the UI know there are new items. ObservableCollectionExtended<T> can be found in the Infragistics.Collections namespace.
Hi Rob,thank you it worked! Now I have another question: how do I get this done with Excel Style Filter? I tried to work with MenuItems like it says here but id doesn't seem to work for me.Best Regards,Daniel
e.MenuItems refers to the items above the search box in the excel style filter. The "Clear" and "Text Filters" items. The code from that forum post you provided was adding items to the Text Filters menu item. I don't think using this would be a good idea if you need to add 100s of items to the filter. However, modifying the filter list below the search box will be difficult as well. That list is mainly provided by the grid and is not exposed so it can't be changed. What you can do though, is retemplate the RecordFilterTreeControl to provide your own tree with a custom ItemsSource. You can provide your own OK button as well and when this is pressed, you can manually apply the filter programmatically.
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamDataPresenter_Add_Filter_Conditions.html
If you want to see what the default RecordFilterTreeControl looks like, you can find a copy of the default style inside your Infragistics installation directory. C:\Program Files (x86)\Infragistics\2014.2\WPF\DefaultStyles\DataPresenter\DataPresenterGeneric_Express.xaml. Search inside this file for RecordFilterTreeControl and the first item that comes up should be the style.
Hi Rob,thank you for this advice but I'm not sure I'm following your thoughts. How can I access to control template of a single filter element? I neet to change the ItemsSource of only one filter for a single column in grid. All the other columns have to stay untouched and work as they work by default.Regards,Daniel
The simplest way to change only one particular column's filter popup would be to use a style similar to this:
<Style x:Key="labelPresenterStyle" TargetType="{x:Type igDP:LabelPresenter}"> <Style.Resources> <Style TargetType="{x:Type igDP:FieldMenuItem}"> <Style.Resources> <Style TargetType="{x:Type igDP:RecordFilterTreeControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordFilterTreeControl}"> <Grid> <!-- custom filter tree control content --> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Style.Resources> </Style> </Style.Resources> </Style>
You can then assign the LabelPresenter style through the Field.Settings.LabelPresenterStyle property.
Let me know if you have any further questions on this matter.
Hi Rob,so how do I access the data context of this column from a style to get the elements for my filter tree?Regards,Daniel
Do you mean how do you access your view model from the style? The RecordFilterTreeControl contains a Field property. From here you can access the DataContext of the XamDataGrid which I would imagine is your view model.
"{Binding Field.Owner.DataPresenter.DataContext, RelativeSource={RelativeSource TemplatedParent}}"
Hi Rob,
thank you, that worked! I have one more question for you: if I implement a property in my ViewModel (a list of strings) and set this property as TreeItems in the control template for the filter this items are not recognized as filter items (I've actually expected that). The question is: is there a simple way to convert them to filter items or should I make a list of checkboxes and implement the filter in code-behind (if yes, how do I set the filter of a XamDataGrid programmatically).Thanks in advance,Daniel