Programmatic filtering issue

2 posts, 0 answers
  1. Sergey
    Sergey avatar
    24 posts
    Member since:
    Oct 2011

    Posted 13 Dec 2012 Link to this post

    I have set column filter programmaticaly. It does filters the view.
    When I click the funnel icon - the default filtering control does not reflect filtering condition.

    using System.Collections.Generic;
    using System.Windows;
    using Telerik.Windows.Data;
     
    namespace TestGridViewFilter
    {
        public partial class MainPage
        {
            public MainPage()
            {
                Documents.Add(new Document { Title = "T1", State = State.Returned });
                Documents.Add(new Document { Title = "T2", State = State.Draft });
                Documents.Add(new Document { Title = "T3", State = State.Final });
                Documents.Add(new Document { Title = "T4", State = State.InReview });
                Documents.Add(new Document { Title = "T5", State = State.New });
                Documents.Add(new Document { Title = "T6", State = State.Submitted });
                Documents.Add(new Document { Title = "T7", State = State.Withdrawn });
                 
                InitializeComponent();
            }
     
            private void SetFilters()
            {
                TestGridView.FilterDescriptors.SuspendNotifications();
     
                TestGridView.FilterDescriptors.Clear();
     
                var statusFilterDescriptor = new CompositeFilterDescriptor();
                statusFilterDescriptor.FilterDescriptors.Add(
                    new FilterDescriptor("State", FilterOperator.IsEqualTo, State.Final));
     
                statusFilterDescriptor.FilterDescriptors.Add(
                    new FilterDescriptor("State", FilterOperator.IsEqualTo, State.Withdrawn));
     
                statusFilterDescriptor.LogicalOperator = FilterCompositionLogicalOperator.Or;
     
                TestGridView.FilterDescriptors.Add(statusFilterDescriptor);
                TestGridView.FilterDescriptors.ResumeNotifications();
            }
     
            private List<Document> _documents;
            public List<Document> Documents
            {
                get { return _documents ?? (_documents = new List<Document>()); }
            }
     
            private void TestGridViewDistinctValuesLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e)
            {
                e.ItemsSource = TestGridView.GetDistinctValues(e.Column, false);
            }
     
            private void UserControlLoaded(object sender, RoutedEventArgs e)
            {
                SetFilters();
            }
        }
     
        public class Document
        {
            public State State { get; set; }
            public string Title { get; set; }
        }
     
        public enum State
        {
            New,
            Draft,
            Withdrawn,
            Submitted,
            InReview,
            Final,
            Returned
        }
    }

                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 mc:Ignorable="d"
                 x:Class="TestGridViewFilter.MainPage"
                 MinWidth="640"
                 MinHeight="480"
                 x:Name="UserControl"
                 Loaded="UserControlLoaded">
     
        <Grid x:Name="LayoutRoot"
              Background="White">
            <telerik:RadGridView x:Name="TestGridView"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Center"
                                 ItemsSource="{Binding Documents, ElementName=UserControl}"
                                 AutoGenerateColumns="False"
                                 IsReadOnly="True"
                                 ShowGroupPanel="False"
                                 RowIndicatorVisibility="Collapsed"
                                 CanUserFreezeColumns="False"
                                 DistinctValuesLoading="TestGridViewDistinctValuesLoading">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Title"
                                                DataMemberBinding="{Binding Title}" />
     
                    <telerik:GridViewDataColumn Header="State"
                                                DataMemberBinding="{Binding State}" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </Grid>
    </UserControl>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Dec 2012 Link to this post

    Hi,

    I would suggest you to use IColumnFilterDescriptor (instead of FilterDescriptor) as demonstrated on this online demo. You can also check our online documentation.

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top