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

CountFunction with Zero Rows

2 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Richard asked on 02 Dec 2020, 07:05 PM

Hi,  How do I get the count function to show '0' when there are no rows on the Grid?  

The aggregate functions all seem to disappear when there are no rows.

Thanks,

Richard

 

<telerik:GridViewColumn.AggregateFunctions>
    <telerik:CountFunction ResultFormatString=" {0}" />
</telerik:GridViewColumn.AggregateFunctions>

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 03 Dec 2020, 12:39 PM

Hello Richard,

Thank you for the provided code snippet. 

The aggregate results in the GridViewFooterCell are displayed by an AggregateResultsList element. When there aren't any items in the ItemsSource of the RadGridView the aggregate results are empty. 

One approach that comes to mind for achieving the desired behavior is to update the ControlTemplate of the GridViewFooterCell. Here is what I have in mind:

<ControlTemplate x:Key="GridViewFooterCellTemplate" TargetType="telerik:GridViewFooterCell">
                <Border x:Name="PART_FooterCellBorder"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid>
                        <TextBlock x:Name="emptyContent"
                                IsHitTestVisible="False"
                                Margin="{TemplateBinding Padding}"
                                Text="0"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Visibility="Collapsed"/>
                        <ContentPresenter
                    Margin="{TemplateBinding Padding}"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding Count}" Value="0">
                        <Setter TargetName="emptyContent" Property="Visibility" Value="Visible" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <Style TargetType="telerik:GridViewFooterCell">
                <Setter Property="Template" Value="{StaticResource GridViewFooterCellTemplate}"/>
            </Style>

With this approach an element is conditionally shown only when the aggregate results are empty. Note, that the Count binding in the DataTrigger refers to the Count property of the DataContext inside the GridViewFooterCell and this approach will work for other aggregate functions as well (not only the CountFunction). Also, note that if you are using the NoXaml dlls, you have to base the style on the default one for the theme. 

Do give this a try and let me know, if it helps. 

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 03 Dec 2020, 11:17 PM

Thank you so much Vladimir, this works perfectly. 

Richard

Tags
GridView
Asked by
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Vladimir Stoyanov
Telerik team
Richard
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or