We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DataTemplate for GridSummaryColumn in WPF

Thread ID:

Created:

Updated:

Platform:

Replies:

151235 Feb 4,2020 06:21 PM UTC Nov 26,2020 02:19 PM UTC WPF 5
loading
Tags: SfDataGrid
Eric BIEF
Asked On February 4, 2020 06:21 PM UTC

Is it a way to use DataTemplate for GridSummaryColumn in WPF ?

Something like :
<syncfusion:GridSummaryColumn
                                        Name="SummaryExecutedQuantity"
                                        Format="'{Sum:n0}'"
                                        MappingName="ExecutedQuantity"
                                        SummaryType="DoubleAggregate">
                                        <syncfusion:GridSummaryColumn.Template>
                                            <DataTemplate>
                                                <TextBlock
                                                    HorizontalAlignment="Center"
                                                    VerticalAlignment="Center"
                                                    FontSize="10"
                                                    Text="{Binding Path=SummaryExecutedQuantity}" />
                                            </DataTemplate>
                                        </syncfusion:GridSummaryColumn.Template>
                                    </syncfusion:GridSummaryColumn>

If yes could give me an example.
Thanks
Eric

Saravanan Ayyanar [Syncfusion]
Replied On February 5, 2020 01:18 PM UTC

Hi Eric, 
 
Thank you for using Syncfusion controls. 
 
We have checked your reported scenario. You are tried correct way to use DataTemplate for GridSummaryColumn in WPF. Please refer the sample link below, 
 
Sample Link: 
 
UG Link: 
 
Please let us know, if you require further assistance on this. 
 
Regards, 
Saravanan A. 


DanielPa
Replied On November 24, 2020 04:08 PM UTC

Hi,
is there always the need of a converter when using a DataTemplate?  
I only need a solution to keep the text prefix for Count localizable.  

<syncfusion:GridSummaryColumn

                                                        Name="Location"

                                                        Format="SomeLocalizedTextNeededHere: {Count:d}'"

                                                        MappingName="Location"

                                                        SummaryType="CountAggregate"/>


Something like:

<syncfusion:GridSummaryColumn

                                                        Name="Location"

                                                        Format="'{Count:d}'"

                                                        MappingName="Location"

                                                        SummaryType="CountAggregate">

                                                        <syncfusion:GridSummaryColumn.Template>

                                                            <DataTemplate>

                                                                <TextBlock>

                                                                    <Run Text="{lex:Loc MyLocalizedTextVar}" />

                                                                    <Run Text="{Binding ??Count??}" />

                                                                </TextBlock>

                                                            </DataTemplate>

                                                        </syncfusion:GridSummaryColumn.Template>

                                                    </syncfusion:GridSummaryColumn>




Vijayarasan Sivanandham [Syncfusion]
Replied On November 25, 2020 01:31 PM UTC

Hi DanielPa,

Thanks for the update.

Yes. You need to use converter for DataTemplate using in GridSummaryColumn in SfDataGrid.

Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


DanielPa
Replied On November 25, 2020 03:33 PM UTC

Thanks for response. So here is my solution. A lot of code, just for a localized prefix. Maybe you have some better ideas!?  
My ItemsSource is a List of "Item" with Id and GroupId as properties. The Grid is grouped by GroupId and AllowDataShaping is active, so the user can move Items to a Group by entering the GroupId. 
I use a single converter for a GroupSummaryColumn and two TableSummaryColumns:


public class SummaryColumnLocalizedPrefixConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var summaryRecordEntry = value as SummaryRecordEntry;

if (summaryRecordEntry == null)
{
return string.Empty;
}

// GroupSummaryRow
if (summaryRecordEntry.Parent is Group parentGroup)
{
return $"{parameter}: {parentGroup.ItemsCount}";
}

// TableSummaryRow
if (summaryRecordEntry.Parent == null)
{
foreach (var summaryValue in summaryRecordEntry.SummaryValues)
{
if ((string)parameter == Properties.Resources.TotalItems &&
summaryValue.Name == nameof(Item.Id))
{
return $"{parameter}: {summaryValue.AggregateValues["Count"]}";
}
if ((string)parameter == Properties.Resources.TotalGroups &&
summaryValue.Name == nameof(Items.GroupId))
{
return $"{parameter}: {summaryValue.AggregateValues["GroupsCount"]}"; //custom Aggregate
}
}
}
return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}


The Xaml for the TableSummary Templates look like this

<syncfusion:SfDataGrid.TableSummaryRows>
<syncfusion:GridSummaryRow ShowSummaryInRow="False">
<syncfusion:GridSummaryRow.SummaryColumns>
<syncfusion:GridSummaryColumn Format="'{Count:d}'" MappingName="Id" SummaryType="CountAggregate">
<syncfusion:GridSummaryColumn.Template>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource SummaryColumnLocalizedPrefixConverter}, UpdateSourceTrigger=PropertyChanged, Mode=OneWay, ConverterParameter={lex:Loc TotalItems}}" />
</DataTemplate>
</syncfusion:GridSummaryColumn.Template>
</syncfusion:GridSummaryColumn>
<syncfusion:GridSummaryColumn CustomAggregate="{StaticResource GroupCountAggregate}" Format="'{GroupsCount:d}'" MappingName="GroupId" SummaryType="Custom">
<syncfusion:GridSummaryColumn.Template>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource SummaryColumnLocalizedPrefixConverter}, UpdateSourceTrigger=PropertyChanged, Mode=OneWay, ConverterParameter={lex:Loc TotalGroups}}" />
</DataTemplate>
</syncfusion:GridSummaryColumn.Template>
</syncfusion:GridSummaryColumn>
</syncfusion:GridSummaryRow.SummaryColumns>
</syncfusion:GridSummaryRow>
</syncfusion:SfDataGrid.TableSummaryRows>

Regards, 
Daniel 

Vijayarasan Sivanandham [Syncfusion]
Replied On November 26, 2020 02:19 PM UTC

Hi DanielPa,

Thanks for the update.

Based on provided information we have checked your provided code snippet from our side this is the best way to achieve your requirement “DataTemplate using in GridSummaryColumn” in SfDataGrid.

Regards,
Vijayarasan S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon