Having problem with compositeFilter.LogicalOperator

1 posts, 0 answers
  1. Snype
    Snype avatar
    9 posts
    Member since:
    Jan 2012

    Posted 06 Mar 2012 Link to this post

    Hi,

    I have created a custom filter control. In The filter control I am displaying a list of available options for the associated column.
    The column may have a values separated by comma or newline.
    For Example a Column value is "Electrical, Mechanical". The filter control has options listed as "Electrical" "Mechanica", "HVAC"..etc. If I select "Electrical" and "Mechanical" in the custom filter screen and click Filter, It should display me all the rows that contains "Electrical" or "Mechanical".

    To achive this I have used a composite filter and set the logical operator to FilterCompositionLogicalOperator.Or
    But it stil gives me the resulting rows where the column contains "Electrical" AND "Mechanical". Is there any way I could make it to display rows contaings data as "Electrical" OR "Mechanical".

    Data Type for the source column is string.

    Please help.
    Thanks in advance

    XML file for the Cusom Filter Control
     
     <TextBlock
     
                    Grid.Row="0"
     
                    Margin="2"
     
                    Text="Show Attributes of Discipline" />
     
                <ListBox
     
                    x:Name="m_oDisciplines"
     
                    Grid.Row="1">               
     
                </ListBox>
     
                <StackPanel Orientation="Horizontal"
     
                            Grid.Row="2">
     
                    <telerik:RadButton
     
                        Name="m_oFilterButton"
     
                        Content="Filter"
     
                        Click="m_oFilterButton_Click"
     
                        Margin="2"
     
                        Width="80" />
     
                    <telerik:RadButton
     
                        Name="m_oClearButton"
     
                        Content="Clear"
     
                        Click="m_oClearButton_Click"
     
                        Margin="2"
     
                        Width="80" />
     
                </StackPanel>
     
      
     
    .CS file portion for the filter control is as below:
     
    public DisciplineFilterCtrl()
     
            {
     
                InitializeComponent();
     
                CreateListBoxWithCheckBox(MetaDataCache.Cache.Disciplines);
     
      
     
            }
     
            private void CreateListBoxWithCheckBox(ObservableCollection<DisciplineWrapper> list)        {
     
      
     
                List<ListBoxItem> listBoxItem = new List<ListBoxItem>();
     
                foreach (DisciplineWrapper item in list)
     
                {
     
                    if (item.Id != Guid.Empty && !item.Deleted)
     
                    {
     
                        ListBoxItem tempItem = new ListBoxItem();
     
                        CheckBox m_oCheckBox = new CheckBox();
     
                        m_oCheckBox.Content = item.Name;
     
                        m_oCheckBox.Tag = item;
     
                        tempItem.Content = m_oCheckBox;
     
                        listBoxItem.Add(tempItem);
     
      
     
                    }
     
                }
     
                m_oDisciplines.ItemsSource = listBoxItem;
     
      
     
            }
     
      
     
     private CompositeFilterDescriptor compositeFilter;
     
     private Telerik.Windows.Controls.GridViewBoundColumnBase column;
     
     private Telerik.Windows.Data.FilterDescriptor[] DisciplineFilter;
     
      
     
    private void CreateFilters()
     
            {
     
                compositeFilter = new CompositeFilterDescriptor();
     
                //compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;
     
                int count = MetaDataCache.Cache.Disciplines.Count;
     
                string dataMember = this.column.DataMemberBinding.Path.Path;
     
                  
     
                DisciplineFilter = new FilterDescriptor[count];
     
                for (int i = 0; i < count; i++)
     
                {
     
                    this.DisciplineFilter[i] = new Telerik.Windows.Data.FilterDescriptor(dataMember
     
                             , Telerik.Windows.Data.FilterOperator.Contains
     
                             , null);
     
                    compositeFilter.FilterDescriptors.Add(DisciplineFilter[i]);
     
                }
     
                compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;
     
            }
     
      
     
            public void Prepare(Telerik.Windows.Controls.GridViewBoundColumnBase column)
     
            {
     
                this.column = column as Telerik.Windows.Controls.GridViewBoundColumnBase;
     
                if (this.column == null)
     
                {
     
                    return;
     
                }
     
                if (this.compositeFilter == null)
     
                {
     
      
     
                    CreateFilters();
     
                }
     
            }
     
      
     
            private void FilterRecord()
     
            {
     
               // this.compositeFilter.FilterDescriptors.Clear();
     
                this.column.DataControl.FilterDescriptors.Clear();
     
                int i = 0;
     
                List<ListBoxItem> listItems = this.m_oDisciplines.ItemsSource as List<ListBoxItem>;
     
                if (null != listItems)
     
                {
     
                    foreach (var item in listItems)
     
                    {
     
                        CheckBox m_oCheckBox = item.Content as CheckBox;
     
                        if (null != m_oCheckBox && m_oCheckBox.IsChecked.Value)
     
                        {
     
      
     
                            //this.compositeFilter.FilterDescriptors.Add(DisciplineFilter[i]);
     
                            this.DisciplineFilter[i].Value = m_oCheckBox.Content;
     
                            this.column.DataControl.FilterDescriptors.Add(DisciplineFilter[i]);
     
                            i++;
     
                        }
     
                    }
     
                }
     
            }
     
      
     
     private void m_oFilterButton_Click(object sender, RoutedEventArgs e)
     
            {
     
                FilterRecord();
     
                this.IsActive = true;
     
            }

Back to Top