This is a migrated thread and some comments may be shown as answers.

ReadOnly Filter descriptor?

2 Answers 135 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pete
Top achievements
Rank 1
Pete asked on 15 May 2012, 10:23 AM
We are pre-populating the RadDataFilter in some places in our application with some filters; e.g. "Customer ID" Is EqualTo "12345". Is there any way to make filters read-only so that they are visible to the user but not editable/removable?
Thanks

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 May 2012, 11:27 AM
Hi,

I am afraid that RadDataFilter does not have such a feature.

Kind regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Pete
Top achievements
Rank 1
answered on 10 Jul 2012, 09:46 AM
It is possible by extracting the templates from the Telerik.Windows.Controls.Data.dll file. I have created a "locked down" version of the datafilter so that the user can only change the operators and search values and nothing else. I post the result here for others:

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"
                    xmlns:dataFilter="clr-namespace:Telerik.Windows.Controls.Data.DataFilter;assembly=Telerik.Windows.Controls.Data"
                    xmlns:Model="clr-namespace:SimpleSearchRadDataFilterTest.Model"
                    xmlns:filteringEditors="clr-namespace:Telerik.Windows.Controls.Filtering.Editors;assembly=Telerik.Windows.Controls">
    <Model:IsNotCompositeFilterConverter x:Name="IsNotCompositeFilterConverter" />
    <telerikData:FilterOperatorConverter x:Key="FilterOperatorConverter" />
    <SolidColorBrush x:Key="FilterControl_InnerBorder" Color="White" />
    <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <dataFilter:LogicalOperatorToCheckedConverter x:Key="LogicalOperatorToCheckedConverter" />
    <telerikData:FilterCompositionLogicalOperatorConverter x:Key="LogicalOperatorConverter" />
    <telerik:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" />
    <SolidColorBrush x:Key="SeparatorBorder" Color="Transparent" />
    <dataFilter:FilterOperatorToSelectedItemConverter x:Key="FilterOperatorToSelectedItemConverter" />
    <dataFilter:FilterMemberToEnabledConverter x:Key="FilterMemberToEnabledConverter" />
    <DataTemplate x:Key="FilterOperatorTemplate">
        <TextBlock Text="{Binding Converter={StaticResource FilterOperatorConverter}}" />
    </DataTemplate>
    <!--Styles-->
    <!--FilterControl-->
    <ControlTemplate x:Key="FilterControlTemplate" TargetType="dataFilter:FilterControl">
        <Border x:Name="OuterBorder" Visibility="{Binding Converter={StaticResource IsNotCompositeFilterConverter}}"
                BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="11">
            <Border.OpacityMask>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Offset="0" Color="Black" />
                    <GradientStop Offset="0.3" />
                </LinearGradientBrush>
            </Border.OpacityMask>
            <Border.Triggers>
                <EventTrigger RoutedEvent="Canvas.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" To="1"
                                             Storyboard.TargetProperty="(UIElement.OpacityMask).(GradientBrush.GradientStops)[0].(GradientStop.Offset)"
                                             Storyboard.TargetName="OuterBorder" />
                            <DoubleAnimation Duration="0:0:0.2" To="1"
                                             Storyboard.TargetProperty="(UIElement.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)"
                                             Storyboard.TargetName="OuterBorder" />
                            <ColorAnimation Duration="0" BeginTime="0:0:0.2" To="Black"
                                            Storyboard.TargetProperty="(UIElement.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                            Storyboard.TargetName="OuterBorder" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Border.Triggers>
            <Border x:Name="InnerBorder" Background="{TemplateBinding Background}"
                    BorderBrush="{StaticResource FilterControl_InnerBorder}" BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="10">
                <StackPanel Orientation="Horizontal" Margin="10,0,10,0">
                    <StackPanel Orientation="Horizontal"
                                Visibility="{Binding IsComposite, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock
Text="{Binding CompositeFilter.LogicalOperator, Converter={StaticResource LogicalOperatorConverter}}"></TextBlock>
                        <telerik:RadToggleButton Visibility="Collapsed" Name="PART_CompositeFilterLogicalOperatorToggleButton"
                                                 Height="18" FontSize="10" MinWidth="30"
                                                 IsChecked="{Binding CompositeFilter.LogicalOperator, Mode=TwoWay, Converter={StaticResource LogicalOperatorToCheckedConverter}}"
                                                 Content="{Binding CompositeFilter.LogicalOperator, Converter={StaticResource LogicalOperatorConverter}}" />
 
                    </StackPanel>
                    <StackPanel Orientation="Horizontal"
                                Visibility="{Binding IsComposite, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
                        <TextBlock x:Name="IRISSimpleFilterMemberLabel"
                                   VerticalAlignment="Center" Margin="0,0,3,0" Text="{Binding SimpleFilter.SelectedMember}" Width="200" />
                        <telerik:RadComboBox Name="PART_SimpleFilterOperatorComboBox"
                                             Margin="0,0,3,0" Width="150" VerticalAlignment="Center"
                                             ItemsSource="{Binding SimpleFilter.AvailableOperators}"
                                             SelectedItem="{Binding SimpleFilter.Operator, Mode=TwoWay, Converter={StaticResource FilterOperatorToSelectedItemConverter}}"
                                             IsEnabled="{Binding SimpleFilter.Member, Converter={StaticResource FilterMemberToEnabledConverter}}"
                                             ItemTemplate="{StaticResource FilterOperatorTemplate}" />
                        <dataFilter:FilterEditor DataContext="{Binding SimpleFilter}" ItemPropertyDefinition="{Binding SelectedMember}"
                                                 FilterOperator="{Binding Operator}" Width="150" IsEnabled="{Binding IsFilterEditorEnabled}"
                                                 HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                    </StackPanel>
                </StackPanel>
            </Border>
        </Border>
    </ControlTemplate>
    <Style x:Key="FilterControlStyle" TargetType="dataFilter:FilterControl">
        <Setter Property="Template" Value="{StaticResource FilterControlTemplate}" />
    </Style>
    <!--DataFilterPresenter-->
    <ControlTemplate x:Key="DataFilterPresenterTemplate" TargetType="dataFilter:DataFilterPresenter">
        <Border Padding="20, 2, 0, 2">
            <Grid x:Name="Root">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <ContentControl x:Name="HeaderContent" Grid.Row="0" Content="{TemplateBinding Header}"
                                ContentTemplate="{TemplateBinding HeaderTemplate}" IsTabStop="False" />
                <ItemsPresenter x:Name="Items" Grid.Row="1" />
            </Grid>
        </Border>
    </ControlTemplate>
    <telerik:HierarchicalDataTemplate x:Key="DataFilterPresenterItemTemplate"
                                      ItemsSource="{Binding CompositeFilter.Filters}">
        <dataFilter:FilterControl Style="{StaticResource FilterControlStyle}" />
    </telerik:HierarchicalDataTemplate>
    <DataTemplate x:Key="DataFilterPresenterHeaderTemplate">
        <dataFilter:FilterControl Style="{StaticResource FilterControlStyle}"/>
    </DataTemplate>
    <Style x:Key="DataFilterPresenterStyle" TargetType="dataFilter:DataFilterPresenter">
        <Setter Property="Template" Value="{StaticResource DataFilterPresenterTemplate}" />
        <Setter Property="ItemTemplate" Value="{StaticResource DataFilterPresenterItemTemplate}" />
        <Setter Property="HeaderTemplate" Value="{StaticResource DataFilterPresenterHeaderTemplate}" />
        <Setter Property="IsTabStop" Value="False" />
    </Style>
    <!--RadDataFilter-->
    <ControlTemplate x:Key="RadDataFilterTemplateSimple" TargetType="telerik:RadDataFilter">
        <ScrollViewer  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                      ScrollViewer.VerticalScrollBarVisibility="Auto">
            <dataFilter:DataFilterPresenter DataContext="{TemplateBinding ViewModel}" Header="{Binding .}"
                                            ItemsSource="{Binding CompositeFilter.Filters}"
                                            Style="{StaticResource DataFilterPresenterStyle}"
                                            />
        </ScrollViewer>
    </ControlTemplate>
    <!--StringFilterEditor-->
    <ControlTemplate x:Key="StringFilterEditorTemplate" TargetType="filteringEditors:StringFilterEditor">
        <Grid MinWidth="100">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                     VerticalAlignment="Stretch"
                     telerik:TextBoxBehavior.UpdateTextOnEnter="True" telerik:TextBoxBehavior.SelectAllOnGotFocus="True" />
        </Grid>
    </ControlTemplate>
    <Style x:Key="StringFilterEditorStyle" TargetType="filteringEditors:StringFilterEditor">
        <Setter Property="Template" Value="{StaticResource StringFilterEditorTemplate}" />
        <Setter Property="IsTabStop" Value="False" />
    </Style>
    <Style TargetType="filteringEditors:StringFilterEditor" BasedOn="{StaticResource StringFilterEditorStyle}" />
</ResourceDictionary>

The IsNotCompositeFilterConverter is used to remove the very top level logical operator:

public class IsNotCompositeFilterConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var root = value as Telerik.Windows.Controls.Data.DataFilter.RootFilterViewModel;
        if (root == null)
        {
            return Visibility.Visible;
        }
 
        return Visibility.Collapsed;
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }
}

To use, just set the template on the RadDataFilter:

<telerik:RadDataFilter Template="{StaticResource RadDataFilterTemplateSimple}" />
Tags
DataFilter
Asked by
Pete
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Pete
Top achievements
Rank 1
Share this question
or