This question is locked. New answers and comments are not allowed.
Hi,
I am using a number of GridView controls, some with defined columns, and some simply set to AutoGenerate. All controls are being bound using MVVM. For some reason when a filter is applied to a grid view that has AutoGeneratColumns set to true, the filter icon does not change and indicate the presence of a filter.
Here is my Xaml for one such grid:
Any ideas?
Regards,
Chris
I am using a number of GridView controls, some with defined columns, and some simply set to AutoGenerate. All controls are being bound using MVVM. For some reason when a filter is applied to a grid view that has AutoGeneratColumns set to true, the filter icon does not change and indicate the presence of a filter.
Here is my Xaml for one such grid:
<grid:RadGridView x:Name="WrappedGridView" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ItemsSource}" HorizontalAlignment="Left" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="True" ShowGroupPanel="False" ShowColumnFooters="True" IsFilteringAllowed="True" IsReadOnly="True" Margin="0" ElementExporting="WrappedGridView_ElementExporting" ClipboardCopyMode="Header,Default" ClipboardPasteMode="None" SelectionMode="Extended" SelectionUnit="Cell"/>Any ideas?
Regards,
Chris
3 Answers, 1 is accepted
0
Hello Chris,
This is strange. Which theme do you use? Can you reproduce the problem in any of our online demos?
Sincerely yours,
Veselin Vasilev
the Telerik team
This is strange. Which theme do you use? Can you reproduce the problem in any of our online demos?
Sincerely yours,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Chris
Top achievements
Rank 1
answered on 04 Nov 2010, 01:03 PM
Hi,
We are using modified versions of a couple of the Telerik themes, but as mentioned the filter selection works fine on defined column grids, and the icon changes to indicate filtering.
Something I failed to mention in my original post is that I am using attached behaviours on the filtering control of each grid (defined or auto generated) in order to modify the filtering behaviour to work more like Excel. Basically clicking the Apply or Clear buttons will perform the necessary filtering actions and then close the filter pop up. (Code posted below). When the Apply button is clicked the Filtering and Filtered events are not firing, but they are when the Clear button is clicked?
Do I need to manually call the OnFiltering() and OnFiltered() events, and if so how can I define the correct parameters for the event args?
Regards,
Chris
Code for filter behaviour:
We are using modified versions of a couple of the Telerik themes, but as mentioned the filter selection works fine on defined column grids, and the icon changes to indicate filtering.
Something I failed to mention in my original post is that I am using attached behaviours on the filtering control of each grid (defined or auto generated) in order to modify the filtering behaviour to work more like Excel. Basically clicking the Apply or Clear buttons will perform the necessary filtering actions and then close the filter pop up. (Code posted below). When the Apply button is clicked the Filtering and Filtered events are not firing, but they are when the Clear button is clicked?
Do I need to manually call the OnFiltering() and OnFiltered() events, and if so how can I define the correct parameters for the event args?
Regards,
Chris
Code for filter behaviour:
namespace Insurer.Analytics.SharedResources.Behaviours { /// <summary> /// A behavior that replicates Excel style filtering where filter are only applied when clicking the Apply button. /// </summary> public class ClosePopupOnApplyFilterBehavior : Behavior<GridViewBoundColumnBase> { FilteringControl customFilteringControl; Button applyFilterButton; Button clearFilterButton; CheckBox selectAllDistinct; System.Windows.Controls.ListBox distinctValuesList; /// <summary> /// Called after the behavior is attached to an AssociatedObject. /// </summary> /// <remarks>Override this to hook up functionality to the AssociatedObject.</remarks> protected override void OnAttached() { // Replace filtering control with custom logic this.customFilteringControl = new FilteringControl(); this.customFilteringControl.Loaded += this.OnFilteringControlLoaded; // Tell the column to use our new "custom" filtering control. // It will never now that this is the default one but spicied up a little. this.AssociatedObject.FilteringControl = customFilteringControl; } void OnFilteringControlLoaded(object sender, RoutedEventArgs e) { // Find controls and associate events this.applyFilterButton = this.customFilteringControl .ChildrenOfType<Button>() .Where(b => b.Name == "PART_ApplyFilterButton") .FirstOrDefault(); if (this.applyFilterButton != null) { this.applyFilterButton.Click += this.OnApplyFilter; } this.clearFilterButton = this.customFilteringControl .ChildrenOfType<Button>() .Where(b => b.Name == "PART_ClearFilterButton") .FirstOrDefault(); if (this.clearFilterButton != null) { this.clearFilterButton.Click += this.OnClearFilter; } // Are distint filters permitted on this column if (this.customFilteringControl.DistinctFiltersVisibility == Visibility.Visible) { this.selectAllDistinct = this.customFilteringControl .ChildrenOfType<CheckBox>() .Where(l => l.Name == "PART_SelectAllCheckBox") .FirstOrDefault(); this.selectAllDistinct.Checked += new RoutedEventHandler(OnSelectAllChecked); this.selectAllDistinct.Unchecked += new RoutedEventHandler(OnSelectAllUnchecked); this.distinctValuesList = this.customFilteringControl .ChildrenOfType<System.Windows.Controls.ListBox>() .Where(l => l.Name == "PART_DistinctValuesList") .FirstOrDefault(); } } void OnApplyFilter(object sender, RoutedEventArgs e) { if (this.customFilteringControl.DistinctFiltersVisibility == Visibility.Visible && this.distinctValuesList != null) { ColumnFilterDescriptor columnDescriptor; bool addDesc = false; var descriptor = this.AssociatedObject.DataControl.FilterDescriptors .Where(desc => ((ColumnFilterDescriptor)desc).Column.GetDataMemberName() == this.AssociatedObject.GetDataMemberName()) .FirstOrDefault(); if (descriptor == null) { // Create new filter if we don't already have one columnDescriptor = new ColumnFilterDescriptor((IDataFieldDescriptor)this.AssociatedObject.DataControl.Columns[this.AssociatedObject.DisplayIndex]); addDesc = true; } else { // Clear distinct values filter from existing filter columnDescriptor = (ColumnFilterDescriptor)descriptor; columnDescriptor.DistinctFilter.DistinctValues.Clear(); } var chks = this.distinctValuesList.ChildrenOfType<CheckBox>(); foreach (var chk in chks) { if (chk.IsChecked.HasValue && chk.IsChecked.Value) { if (this.AssociatedObject.DataType == typeof(bool)) { if (string.Compare(chk.Content.ToString().ToLower(), "true") == 0) { columnDescriptor.DistinctFilter.DistinctValues.Add(true); } else { columnDescriptor.DistinctFilter.DistinctValues.Add(false); } } else { columnDescriptor.DistinctFilter.DistinctValues.Add(chk.Content); } } } if (addDesc && columnDescriptor.DistinctFilter.DistinctValues.Count > 0) { this.AssociatedObject.DataControl.FilterDescriptors.Add(columnDescriptor); } } // And when clicked find the parent popup and close it. var popup = applyFilterButton.ParentOfType<System.Windows.Controls.Primitives.Popup>(); if (popup != null) { popup.IsOpen = false; } } void OnSelectAllChecked(object sender, RoutedEventArgs e) { SelectAll(true); } void OnSelectAllUnchecked(object sender, RoutedEventArgs e) { SelectAll(false); } private void SelectAll(bool check) { if (this.selectAllDistinct != null && this.distinctValuesList != null) { // Check / uncheck items var chks = this.distinctValuesList.ChildrenOfType<CheckBox>(); foreach (var chk in chks) { chk.IsChecked = check; } // Set view model property ((FilteringViewModel)this.customFilteringControl.DataContext).SelectAll = check; } } void OnClearFilter(object sender, RoutedEventArgs e) { // And when clicked find the parent popup and close it. var popup = clearFilterButton.ParentOfType<System.Windows.Controls.Primitives.Popup>(); if (popup != null) { popup.IsOpen = false; } } /// <summary> /// Called when the behavior is being detached from its AssociatedObject, /// but before it has actually occurred. /// </summary> /// <remarks>Override this to unhook functionality from the AssociatedObject.</remarks> protected override void OnDetaching() { if (this.applyFilterButton != null) { this.applyFilterButton.Click -= this.OnApplyFilter; } if (this.clearFilterButton != null) { this.clearFilterButton.Click -= this.OnClearFilter; } if (this.selectAllDistinct != null) { this.selectAllDistinct.Checked -= this.OnSelectAllChecked; this.selectAllDistinct.Unchecked -= this.OnSelectAllUnchecked; } this.customFilteringControl.Loaded -= this.OnFilteringControlLoaded; } } }0
Hi Chris,
I could not reproduce the problem with our Q3 2010 Beta version. Please find attached a sample project based on your code. Try filtering the Name column - you will see that the funnel is colored appropriately.
All the best,
Veselin Vasilev
the Telerik team
I could not reproduce the problem with our Q3 2010 Beta version. Please find attached a sample project based on your code. Try filtering the Name column - you will see that the funnel is colored appropriately.
All the best,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items