Skip to content

Commit 8275b94

Browse files
Merge pull request #7100 from syncfusion-content/983330-Style1UB
983330: Updated the UG Content and Samples for Style and appearance folder in DataGrid
2 parents c4b4a38 + 937b71b commit 8275b94

File tree

5 files changed

+541
-491
lines changed

5 files changed

+541
-491
lines changed
Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
---
22
layout: post
3-
title: Aggregate customization in Blazor DataGrid | Syncfusion
4-
description: Learn here all about aggregate in Syncfusion Blazor DataGrid and more.
3+
title: Customize aggregates in Blazor DataGrid | Syncfusion
4+
description: Learn how to customize aggregate rows in the Syncfusion Blazor DataGrid using CSS, including footer containers and summary cells.
55
platform: Blazor
66
control: DataGrid
77
documentation: ug
88
---
99

10-
# Aggregate in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid
10+
# Aggregate customization in Syncfusion Blazor DataGrid
1111

12-
You can customize the appearance of aggregate elements in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid using CSS. Below are examples of how to customize the aggregate root element and the aggregate cell elements.
12+
Aggregates are displayed as summary rows in the DataGrid footer, providing a consolidated view of totals, averages, or counts. These rows can be styled using CSS to match the layout and design of the grid. Styling options are available for:
1313

14-
## Customizing the aggregate root element
14+
- **Aggregate root container:** The outer wrapper of the footer row.
15+
- **Aggregate summary row and cells:** The row that shows summary values, and the cells that display each result.
1516

16-
To customize the appearance of the Grid's aggregate root elements, you can use the following CSS code:
17+
## Customize the aggregate root element
18+
The **.e-gridfooter** class styles the root container of the aggregate footer row. Use CSS to adjust its appearance:
1719

1820
```css
1921
.e-grid .e-gridfooter {
2022
font-family: cursive;
2123
}
2224
```
2325

24-
In this example, the **e-gridfooter** class represents the root element of the aggregate row in the Grid footer. You can modify the `font-family` property to change the font of the aggregate root element.
26+
Properties like **font-family**, **font-size**, and **padding** can be changed to fit the grid layout design.
2527

26-
![Customize aggregate root element](../images/style-and-appearance/aggregate-root-element.png)
28+
![Aggregate footer root with custom font](../images/style-and-appearance/aggregate-root-element.png)
2729

28-
## Customizing the aggregate cell elements
30+
## Customize the aggregate cell elements
2931

30-
To customize the appearance of the Grid's aggregate cell elements (summary row cell elements), you can use the following CSS code:
32+
The **.e-summaryrow** and **.e-summarycell** classes define the appearance of the summary row and its individual cells in the Blazor DataGrid. Apply CSS to modify their look:
3133

3234
```css
3335
.e-grid .e-summaryrow .e-summarycell {
3436
background-color: #deecf9;
3537
}
3638
```
3739

38-
In this example, the **e-summaryrow** class represents the summary row containing aggregate cells, and the **e-summarycell** class targets individual aggregate cells within the summary row. You can modify the `background-color` property to change the `color` of the aggregate cell elements.
40+
Properties such as **background-color**, **color**, and **text-align** can be adjusted to improve clarity and interaction.
3941

40-
![Customize aggregate cell element](../images/style-and-appearance/aggregate-cell-element.png)
42+
![Aggregate summary cell with custom background color](../images/style-and-appearance/aggregate-cell-element.png)
4143

4244
{% tabs %}
4345
{% highlight razor tabtitle="Index.razor" %}
4446

4547
@using Syncfusion.Blazor.Grids
4648

47-
<SfGrid @ref="Grid" DataSource="@Orders" Height="315" AllowPaging="true">
49+
<SfGrid DataSource="@Orders" Height="315" AllowPaging="true">
4850
<GridPageSettings PageSize="8"></GridPageSettings>
4951
<GridAggregates>
5052
<GridAggregate>
5153
<GridAggregateColumns>
52-
<GridAggregateColumn Field=@nameof(OrderData.Freight) Type="AggregateType.Sum" >
54+
<GridAggregateColumn Field=@nameof(OrderData.Freight) Type="AggregateType.Sum">
5355
<FooterTemplate>
5456
@{
5557
var aggregate = (context as AggregateTemplateContext);
56-
<div>
57-
<p>Sum: @aggregate.Sum</p>
58-
</div>
58+
<div class="aggregate-chip">Sum: @aggregate.Sum</div>
5959
}
6060
</FooterTemplate>
6161
</GridAggregateColumn>
@@ -67,36 +67,30 @@ In this example, the **e-summaryrow** class represents the summary row containin
6767
<FooterTemplate>
6868
@{
6969
var aggregate = (context as AggregateTemplateContext);
70-
<div>
71-
<p>Max: @aggregate.Max</p>
72-
</div>
70+
<div class="aggregate-chip">Max: @aggregate.Max</div>
7371
}
7472
</FooterTemplate>
7573
</GridAggregateColumn>
7674
</GridAggregateColumns>
7775
</GridAggregate>
7876
</GridAggregates>
7977
<GridColumns>
80-
<GridColumn Field=@nameof(OrderData.OrderID) HeaderText="Order ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right" Width="140"></GridColumn>
78+
<GridColumn Field=@nameof(OrderData.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="140"></GridColumn>
8179
<GridColumn Field=@nameof(OrderData.CustomerID) HeaderText="Customer ID" Width="120"></GridColumn>
82-
<GridColumn Field=@nameof(OrderData.Freight) HeaderText="Freight" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right" Width="120"></GridColumn>
83-
<GridColumn Field=@nameof(OrderData.OrderDate) HeaderText="Order Date" Format="d" Width="100" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></GridColumn>
80+
<GridColumn Field=@nameof(OrderData.Freight) HeaderText="Freight" TextAlign="TextAlign.Right" Width="120"></GridColumn>
81+
<GridColumn Field=@nameof(OrderData.OrderDate) HeaderText="Order Date" Format="d" TextAlign="TextAlign.Right" Width="110"></GridColumn>
8482
</GridColumns>
8583
</SfGrid>
8684

8785
<style>
88-
.e-grid .e-gridfooter {
89-
font-family: cursive;
90-
}
91-
.e-grid .e-summaryrow .e-summarycell {
92-
background-color: #deecf9;
93-
}
86+
.e-grid .e-gridfooter { font-family: cursive; background-color: #f5f8fc; }
87+
.e-grid .e-summaryrow .e-summarycell { background-color: #deecf9; }
88+
.aggregate-chip { padding: 4px 8px; border-radius: 6px; background-color: #fff; border: 1px solid #bcd3ea; display: inline-block; min-width: 120px; text-align: center; color: #0b3f73; font-weight: 600; }
89+
.e-grid .e-summarycell:focus-visible { outline: 2px solid #005a9e; outline-offset: -2px; }
9490
</style>
9591

9692
@code {
97-
private SfGrid<OrderData> Grid;
98-
public List<OrderData> Orders { get; set; }
99-
93+
private List<OrderData> Orders { get; set; }
10094
protected override void OnInitialized()
10195
{
10296
Orders = OrderData.GetAllRecords();
@@ -107,44 +101,43 @@ In this example, the **e-summaryrow** class represents the summary row containin
107101

108102
{% highlight c# tabtitle="OrderData.cs" %}
109103

110-
public class OrderData
104+
internal sealed class OrderData
111105
{
112-
public static List<OrderData> Orders = new List<OrderData>();
106+
private static readonly List<OrderData> Data = new();
113107

114108
public OrderData(int orderID, string customerID, double freight, DateTime orderDate)
115109
{
116-
this.OrderID = orderID;
117-
this.CustomerID = customerID;
118-
this.Freight = freight;
119-
this.OrderDate = orderDate;
110+
OrderID = orderID;
111+
CustomerID = customerID;
112+
Freight = freight;
113+
OrderDate = orderDate;
120114
}
121115

122-
public static List<OrderData> GetAllRecords()
116+
internal static List<OrderData> GetAllRecords()
123117
{
124-
if (Orders.Count == 0)
118+
if (Data.Count == 0)
125119
{
126-
Orders.Add(new OrderData(10248, "VINET", 32.38, new DateTime(2024, 1, 10)));
127-
Orders.Add(new OrderData(10249, "TOMSP", 11.61, new DateTime(2024, 1, 11)));
128-
Orders.Add(new OrderData(10250, "HANAR", 65.83, new DateTime(2024, 1, 12)));
129-
Orders.Add(new OrderData(10251, "VICTE", 41.34, new DateTime(2024, 1, 13)));
130-
Orders.Add(new OrderData(10252, "SUPRD", 51.3, new DateTime(2024, 1, 14)));
131-
Orders.Add(new OrderData(10253, "HANAR", 58.17, new DateTime(2024, 1, 15)));
132-
Orders.Add(new OrderData(10254, "CHOPS", 22.98, new DateTime(2024, 1, 16)));
133-
Orders.Add(new OrderData(10255, "RICSU", 148.33, new DateTime(2024, 1, 17)));
134-
Orders.Add(new OrderData(10256, "WELLI", 13.97, new DateTime(2024, 1, 18)));
135-
Orders.Add(new OrderData(10257, "HILAA", 81.91, new DateTime(2024, 1, 19)));
120+
Data.Add(new OrderData(10248, "VINET", 32.38, new DateTime(2024, 1, 10)));
121+
Data.Add(new OrderData(10249, "TOMSP", 11.61, new DateTime(2024, 1, 11)));
122+
Data.Add(new OrderData(10250, "HANAR", 65.83, new DateTime(2024, 1, 12)));
123+
Data.Add(new OrderData(10251, "VICTE", 41.34, new DateTime(2024, 1, 13)));
124+
Data.Add(new OrderData(10252, "SUPRD", 51.30, new DateTime(2024, 1, 14)));
125+
Data.Add(new OrderData(10253, "HANAR", 58.17, new DateTime(2024, 1, 15)));
126+
Data.Add(new OrderData(10254, "CHOPS", 22.98, new DateTime(2024, 1, 16)));
127+
Data.Add(new OrderData(10255, "RICSU", 148.33, new DateTime(2024, 1, 17)));
128+
Data.Add(new OrderData(10256, "WELLI", 13.97, new DateTime(2024, 1, 18)));
129+
Data.Add(new OrderData(10257, "HILAA", 81.91, new DateTime(2024, 1, 19)));
136130
}
137-
138-
return Orders;
131+
return Data;
139132
}
140133

141-
public int OrderID { get; set; }
142-
public string CustomerID { get; set; }
143-
public double Freight { get; set; }
144-
public DateTime OrderDate { get; set; }
134+
public int OrderID { get; }
135+
public string CustomerID { get; }
136+
public double Freight { get; }
137+
public DateTime OrderDate { get; }
145138
}
146139

147140
{% endhighlight %}
148141
{% endtabs %}
149142

150-
{% previewsample "https://blazorplayground.syncfusion.com/BNLoXStLKgmIIyaI" %}
143+
{% previewsample "https://blazorplayground.syncfusion.com/embed/hXhIMNMcivWmiUmh?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}

0 commit comments

Comments
 (0)