public void SetColumnFilter() { var existingFilteredColumnDefinition = FilteredColumnInfo.FirstOrDefault(x => x.Column.FieldName == CurrentColumnInfo.Column.FieldName); if (CurrentColumnInfo.RowValues.Select(x => x.ListItem).All(x => x.IsSelected)) { FilteredColumnInfo.Remove(existingFilteredColumnDefinition); } else { var currentFilteredRowValues = new ObservableCollection <RowData>(); foreach (var rowValue in CurrentColumnInfo.RowValues.Where(x => x.ListItem.IsSelected)) { currentFilteredRowValues.Add(rowValue); } if (existingFilteredColumnDefinition != null) { existingFilteredColumnDefinition.RowValues = currentFilteredRowValues; } else { FilteredColumnInfo.Add(new ColumnInfo() { Column = CurrentColumnInfo.Column, RowValues = currentFilteredRowValues }); } } ApplyFilter(); }
public void ClearColumnFilter(string fieldName) { var existingFilteredColumnDefinition = FilteredColumnInfo.FirstOrDefault(x => x.Column.FieldName == fieldName); if (existingFilteredColumnDefinition != null) { FilteredColumnInfo.Remove(existingFilteredColumnDefinition); } }
public ObservableCollection <CheckedListItem> GetDistinctColumnValues() { if (CollectionViewSource.GetDefaultView(CurrentExtendedDatagrid.ItemsSource) == null) { return(null); } var isColumnFiltered = IsCurrenColumnFiltered(); var distinctRowValues = new List <object>(); var dataType = GetDataType(); if (CurrentColumnInfo.Column.IsDefaultBinding) { distinctRowValues.AddRange(CurrentExtendedDatagrid.ItemsSource.SelectExpression <object>( CurrentColumnInfo.Column.FieldName.GetSelectLamdaExpressionPredicate(CurrentColumnInfo.Column.IsNullableBinding), null).Distinct().ToList()); foreach (var rowValue in distinctRowValues) { InsertRowValue(rowValue, dataType.GetDisplayValue(rowValue), dataType); } } else { var datagridCells = DatagridRows.First(c => c.Key == CurrentColumnInfo.Column).Value; foreach (var row in datagridCells) { var textBlock = FindDataGridControl.GetTextBlock(row); var rowValue = textBlock.DataContext.GetPropertyValue(CurrentColumnInfo.Column.FieldName); if (distinctRowValues.Contains(rowValue)) { continue; } distinctRowValues.Add(rowValue); InsertRowValue(rowValue, dataType.GetDisplayValue(textBlock.Text, false), dataType); } } CurrentColumnInfo.RowValues.ToList().ForEach(x => x.ListItem.IsSelected = !isColumnFiltered); if (isColumnFiltered) { var existingFilteredRowValues = FilteredColumnInfo.First(x => x.Column.FieldName == CurrentColumnInfo.Column.FieldName).RowValues; foreach (var existingFilteredRowValue in existingFilteredRowValues) { var listItem = CurrentColumnInfo.RowValues.FirstOrDefault(x => x.DisplayRowValue == existingFilteredRowValue.DisplayRowValue); if (listItem != null) { listItem.ListItem.IsSelected = true; } } } var currentFilteredRowValues = new ObservableCollection <CheckedListItem>(); foreach (var listItem in CurrentColumnInfo.RowValues.Select(x => x.ListItem)) { currentFilteredRowValues.Add(listItem); } return(currentFilteredRowValues); }
public bool IsCurrenColumnFiltered() { return(FilteredColumnInfo.Any(x => x.Column.FieldName == CurrentColumnInfo.Column.FieldName)); }