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

Get filter values number

18 Answers 184 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Iron
Valentin asked on 29 Apr 2016, 03:09 PM

Hello,

I want to know the number of filter values in my RadGridView.

I know that gridVariables.FilterDescriptors.Count gives me the value '0' or '1' if a filter value is selected, but, i don't find how i can get the number of selected values in the filter.

 

Thank you.

 

Valentin.

18 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 May 2016, 10:43 AM
Hello Valentin,

You can find the filter descriptor of the column and get its distinct values. For example:
var columnFilter = (this.clubsGrid.Columns[1] as GridViewDataColumn).ColumnFilterDescriptor.DistinctFilter;
        var selectedDistinctValuesCount = columnFilter.DistinctValues.Count();


Regards,
Maya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 02 May 2016, 11:54 AM

Hi,

Thank you for your help.

 

Now, i know how many distincts values I have selected. But, how can I know how many values there are in total ?

gridVariables.FilterDescriptors.Count returns just '0' or '1'.

 

Thank you !

 

Valentin.

0
Maya
Telerik team
answered on 02 May 2016, 12:40 PM
Hello Valentin,

The number of distinct values will be equal to the number of the different values of the property bound to the column. You can get it directly from the source of the grid. More information can be found in those StackOverflow threads:
1. LINQ: Distinct values
2. LINQ's Distinct() on a particular property
3.  query to return distinct field values from a list of objects



Regards,
Maya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 02 May 2016, 03:01 PM

Hi,

 

I tried this : var nbTot = this.gridVariables..FilterDescriptors.Distinct().Count(); but it returns just '1' or '0' too.

I do not arrive with you'r links.

 

Valentin.

 

0
Valentin
Top achievements
Rank 1
Iron
answered on 02 May 2016, 03:57 PM

Re,

 

With var nbTot = this.gridVariables.Items.Count; , I've got the total number of gridview rows, but I don't know how I can compare nbTot with the total of selected filter values.

With you'r code I have just the distincts values, and i do not arrive to get this for the total number of rows.

 

Thank you.

Valentin.

0
Valentin
Top achievements
Rank 1
Iron
answered on 02 May 2016, 04:00 PM

Re,

 

With var nbTot = this.gridVariables.Items.Count; , I've got the total number of GridView Rows, but I do not arrive to get the distincts values.

 

Thank you.

Valentin.

0
Maya
Telerik team
answered on 03 May 2016, 06:18 AM
Hi Valentin,

You need to get all the items that are with distinct values for a property. Based on the links I provided, you can try something as follows:
var distinctNamesCount = gridsSourceCollection.Select(o => o.Name).Distinct().Count();

Where 'Name' is a property of your business object that you want to use for distinguishing the items. 

Regards,
Maya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 03 May 2016, 11:59 AM

Hi,

 

With : var distinctNamesCount = gridVariables.Select(o => o.Name).Distinct().Count(); , I've this error for "o => o.Name" : "Impossible de convertir expression lambda en type 'System.Collections.IEnumerable', car il ne s'agit pas d'un type délégué"

0
Maya
Telerik team
answered on 04 May 2016, 08:58 AM
Hello Valentin,

Attached is a small project illustrating the suggested approach. 

Regards,
Maya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 12 Sep 2016, 09:52 AM

Hello Maya,

 

I have a question : I want to know if is it possible to do not display the area for checkbox values in the filter.

You can see in the attached file :

- The area that I want to hide is under the red cross.

- I want to display just the part in the red circle.

 

Thank you !

0
Dilyan Traykov
Telerik team
answered on 12 Sep 2016, 12:22 PM
Hello Valentin,

The desired result can be achieved by simply setting the ShowDistinctFilters property of the respective column to False.

Please let me know if this works for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 12 Sep 2016, 01:36 PM

Hello Dilyan,

 

I do this, before your answer :

e.ItemsSource = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, true, 0);

 

It's the same result by your technic ?

 

(Result in attached file)

 

Thanks

0
Dilyan Traykov
Telerik team
answered on 12 Sep 2016, 02:55 PM
Hello Valentin,

I'm afraid I'm unable to open the attached file you provided, but there should not be any difference between the two approaches - I assume you're using the DistinctValuesLoading event and setting the maximumValueCount to 0 .

If that is the case, you're free to choose whichever approach you find more suitable for your scenario.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 12 Sep 2016, 02:59 PM

Hello,

 

I'm sorry, I forgotten to rename the file ! There is the new file.

 

Sorry for the desagreement.

0
Dilyan Traykov
Telerik team
answered on 12 Sep 2016, 03:09 PM
Hello Valentin,

After further observation, I believe you'd be better off using the ShowDistinctFilters property as it hides the whole StackPanel in which the values reside along with the SelectAll checkbox, as opposed to the other approach where these elements are still visible, even though the content of the StackPanel is empty.

I apologize for this misunderstanding and hope that setting the ShowDistinctFilters works for you. Please let me know if you have any further questions or concerns.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 13 Sep 2016, 07:35 AM

Hello Dilyan,

 

I realised that your solution is better. With my code, all filters (for each column) has got 0 values. With your technic, I can choose for each filter (and so for each column) if I want display or not the values.

 

Result in attached file :)

 

But the cross to close the filter is on my text. I should to increase the width of the filter ?

 

Thank you very much !

0
Dilyan Traykov
Telerik team
answered on 13 Sep 2016, 12:33 PM
Hello Valentin,

You can modify the template of the Filtering Control to your liking in order to achieve the desired look. Here's a style I've extracted for the VisualStudio2013 theme (which I assume you've used):

<Style TargetType="{x:Type telerik:FilteringControl}" BasedOn="{StaticResource FilteringControlStyle}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:FilteringControl}">
                <Grid Background="Transparent" SnapsToDevicePixels="True">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{TemplateBinding Padding}">
                        <Grid>
                            <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <Grid>
                                    <StackPanel x:Name="PART_DistinctFilter" Visibility="{TemplateBinding DistinctFiltersVisibility}">
                                        <CheckBox x:Name="PART_SelectAllCheckBox" Content="Select All" IsChecked="{Binding SelectAll, Mode=TwoWay}" Margin="-1,0,0,5" telerik:LocalizationManager.ResourceKey="GridViewFilterSelectAll"/>
                                        <ListBox x:Name="PART_DistinctValuesList" Background="{DynamicResource {x:Static telerik:VisualStudio2013ResourceKey.MainBrush}}" ScrollViewer.HorizontalScrollBarVisibility="Auto" SelectionMode="Multiple">
                                            <ListBox.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <VirtualizingStackPanel IsItemsHost="True" MaxHeight="242"/>
                                                </ItemsPanelTemplate>
                                            </ListBox.ItemsPanel>
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}" VerticalAlignment="Center">
                                                        <Binding Path="ConvertedValue">
                                                            <Binding.Converter>
                                                                <telerik:DistinctValueConverter/>
                                                            </Binding.Converter>
                                                        </Binding>
                                                    </CheckBox>
                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                            <ListBox.ItemContainerStyle>
                                                <Style TargetType="{x:Type ListBoxItem}">
                                                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                                                    <Setter Property="VerticalContentAlignment" Value="Top"/>
                                                    <Setter Property="Template">
                                                        <Setter.Value>
                                                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                                <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </ListBox.ItemContainerStyle>
                                        </ListBox>
                                    </StackPanel>
                                    <telerik:RadButton x:Name="PART_FilterCloseButton" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Grid.Column="1" HorizontalAlignment="Right" Height="12" Margin="0,9,9,0" MinHeight="0" Padding="0" VerticalAlignment="Top" Width="12">
                                        <Grid UseLayoutRounding="True">
                                            <Path Data="M1,0L4,3 7,0 8,1 5,4 8,7 7,8 4,5 1,8 0,7 3,4 0,1z" Fill="{DynamicResource {x:Static telerik:VisualStudio2013ResourceKey.StrongBrush}}" HorizontalAlignment="Center" Height="8" Stretch="Fill" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="8"/>
                                            <Path Data="M1,0L4,3 7,0 8,1 5,4 8,7 7,8 4,5 1,8 0,7 3,4 0,1z" Fill="{DynamicResource {x:Static telerik:VisualStudio2013ResourceKey.SelectedBrush}}" HorizontalAlignment="Center" Height="8" Stretch="Fill" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="8">
                                                <Path.Visibility>
                                                    <Binding ElementName="PART_FilterCloseButton" Path="IsPressed">
                                                        <Binding.Converter>
                                                            <telerik:BooleanToVisibilityConverter/>
                                                        </Binding.Converter>
                                                    </Binding>
                                                </Path.Visibility>
                                            </Path>
                                        </Grid>
                                    </telerik:RadButton>
                                </Grid>
                                <StackPanel Visibility="{TemplateBinding FieldFiltersVisibility}">
                                    <TextBlock Foreground="{DynamicResource {x:Static telerik:VisualStudio2013ResourceKey.MarkerBrush}}" Margin="0,2,0,0" telerik:LocalizationManager.ResourceKey="GridViewFilterShowRowsWithValueThat" Text="Show rows with value that"></TextBlock>
                                    <telerik:RadComboBox x:Name="PART_Filter1ComboBox" FilteringBehavior="{x:Null}" Margin="0,4,0,0" MinHeight="22">
                                        <telerik:RadComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock>
                                                    <TextBlock.Text>
                                                        <Binding>
                                                            <Binding.Converter>
                                                                <telerik:FilterOperatorConverter/>
                                                            </Binding.Converter>
                                                        </Binding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </DataTemplate>
                                        </telerik:RadComboBox.ItemTemplate>
                                    </telerik:RadComboBox>
                                    <ContentControl x:Name="PART_Filter1ContentControl" HorizontalContentAlignment="Stretch" Margin="0,4,0,0" VerticalContentAlignment="Stretch">
                                        <ContentControl.IsEnabled>
                                            <Binding Path="Operator">
                                                <Binding.Converter>
                                                    <telerik:FilterOperatorToFilterEditorIsEnabledConverter/>
                                                </Binding.Converter>
                                            </Binding>
                                        </ContentControl.IsEnabled>
                                    </ContentControl>
                                    <telerik:RadComboBox x:Name="PART_LogicalOperatorsComboBox" FilteringBehavior="{x:Null}" Margin="0,4,0,0" MinHeight="22">
                                        <telerik:RadComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock>
                                                    <TextBlock.Text>
                                                        <Binding>
                                                            <Binding.Converter>
                                                                <telerik:FilterCompositionLogicalOperatorConverter/>
                                                            </Binding.Converter>
                                                        </Binding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </DataTemplate>
                                        </telerik:RadComboBox.ItemTemplate>
                                    </telerik:RadComboBox>
                                    <telerik:RadComboBox x:Name="PART_Filter2ComboBox" FilteringBehavior="{x:Null}" Margin="0,4,0,0" MinHeight="22">
                                        <telerik:RadComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock>
                                                    <TextBlock.Text>
                                                        <Binding>
                                                            <Binding.Converter>
                                                                <telerik:FilterOperatorConverter/>
                                                            </Binding.Converter>
                                                        </Binding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </DataTemplate>
                                        </telerik:RadComboBox.ItemTemplate>
                                    </telerik:RadComboBox>
                                    <ContentControl x:Name="PART_Filter2ContentControl" HorizontalContentAlignment="Stretch" Margin="0,4,0,0" VerticalContentAlignment="Stretch">
                                        <ContentControl.IsEnabled>
                                            <Binding Path="Operator">
                                                <Binding.Converter>
                                                    <telerik:FilterOperatorToFilterEditorIsEnabledConverter/>
                                                </Binding.Converter>
                                            </Binding>
                                        </ContentControl.IsEnabled>
                                    </ContentControl>
                                </StackPanel>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <Button x:Name="PART_ApplyFilterButton" Content="Filter" Margin="0,4,4,0" MinWidth="87" telerik:LocalizationManager.ResourceKey="GridViewFilter" Visibility="{TemplateBinding FilterButtonVisibility}"/>
                                    <Button x:Name="PART_ClearFilterButton" Content="Clear Filter" Grid.Column="1" Margin="0,4,0,0" MinWidth="87" telerik:LocalizationManager.ResourceKey="GridViewClearFilter"/>
                                </Grid>
                            </StackPanel>
                        </Grid>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Of course, you're free to extract the template for any of the themes and modify it to your liking.

Do let me know how this goes.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Valentin
Top achievements
Rank 1
Iron
answered on 13 Sep 2016, 01:08 PM

Hello Dilyan,

 

I'm using VS 2010 ^^'... But I will look your code for adapt it.

 

Thank you very much !

Tags
GridView
Asked by
Valentin
Top achievements
Rank 1
Iron
Answers by
Maya
Telerik team
Valentin
Top achievements
Rank 1
Iron
Dilyan Traykov
Telerik team
Share this question
or