Server-side filter with FilterDescriptors

  • carped99 2 years, 7 months ago

    Hi!
    I’m trying to load big data by using the C1DataSource and EntityViewSource

    C1DataSource  DataSource = new C1DataSource 
    {
         ObjectContextType = typeof(MyEntities) 
    };
    DataSource.ViewSources.Add(new C1.Data.Entities.EntityViewSource
    {
                    EntitySetName = "MyEntityName",
                    PageSize = 100,
                    VirtualMode = C1.Data.DataSource.VirtualModeKind.Managed,
     });

    and I want to set filter like " (A=1 or A=2) and (B=1 or B=2)"

    DataSource.ViewSources[0].FilterDescriptors.Add(new C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsEqualTo,
                    PropertyPath = "A",
                    Value = 1
    });
    
    DataSource.ViewSources[0].FilterDescriptors.Add(new C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsEqualTo,
                    PropertyPath = "A",
                    Value = 2
    });
    C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsEqualTo,
                    PropertyPath = "B",
                    Value = 1
    });
    
    DataSource.ViewSources[0].FilterDescriptors.Add(new C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsEqualTo,
                    PropertyPath = "B",
                    Value = 2
    });
    

    but, it don’t work as I expected…

    how can I set the FilterDescriptor for " (A=1 or A=2) and (B=1 or B=2)" ?

  • 3p
    C1_NodirT3p 2 years, 7 months ago

    Hello,

    For this case you can use the IsContainedIn operator.

    Example in C#:

    DataSource.ViewSources[0].FilterDescriptors.Add(new C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsContainedIn,
                    PropertyPath = "A",
                    Value = new int[] {1, 2}
    });
    DataSource.ViewSources[0].FilterDescriptors.Add(new C1.Data.DataSource.FilterDescriptor
    {
                    Operator = C1.Data.DataSource.FilterOperator.IsContainedIn,
                    PropertyPath = "B",
                    Value = new int[] {1, 2}
    });

    Example in XAML:

    <c1:C1DataSource x:Name="dataSrc" ObjectContextType="{x:Type local:MyEntities}">
        <c1:EntityViewSource EntitySetName="MyEntityName" PageSize="10" VirtualMode="Managed">
            <c1:EntityViewSource.FilterDescriptors>
                <c1:FilterDescriptor PropertyPath="A" Operator="IsContainedIn">
                    <c1:FilterDescriptor.Value>
                        <x:Array Type="{x:Type sys:Int32}">
                            <sys:Int32>1</sys:Int32>
                            <sys:Int32>2</sys:Int32>
                        </x:Array>
                    </c1:FilterDescriptor.Value>
                </c1:FilterDescriptor>
                <c1:FilterDescriptor PropertyPath="B" Operator="IsContainedIn">
                    <c1:FilterDescriptor.Value>
                        <x:Array Type="{x:Type sys:Int32}">
                            <sys:Int32>1</sys:Int32>
                            <sys:Int32>2</sys:Int32>
                        </x:Array>
                    </c1:FilterDescriptor.Value>
                </c1:FilterDescriptor>
            </c1:EntityViewSource.FilterDescriptors>
        </c1:EntityViewSource>
    </c1:C1DataSource>
    

    where XML namespaces are

    xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml&quot;
            xmlns:local="clr-namespace:[[MyApplicationNamespace]]"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
    

    Also, since you use VirtualModeKind.Managed, do not forget to set a ControlHandler to your grid. Otherwise use VirtualModeKind.Unmanaged

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.