Skip to content

Commit 71cacce

Browse files
committed
Docs updated
1 parent d7bb62e commit 71cacce

File tree

2 files changed

+85
-9
lines changed

2 files changed

+85
-9
lines changed

BlazorBootstrap.Demo.RCL/Components/Pages/Grid/16-summary/Grid_Demo_01_Summary_Example.razor

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
@code {
3030
private IEnumerable<Employee> employees = default!;
3131

32-
private HashSet<Employee> selectedEmployees = new();
33-
3432
private async Task<GridDataProviderResult<Employee>> EmployeesDataProvider(GridDataProviderRequest<Employee> request)
3533
{
3634
if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging
@@ -58,12 +56,6 @@
5856
};
5957
}
6058

61-
private Task OnSelectedItemsChanged(HashSet<Employee> employees)
62-
{
63-
selectedEmployees = employees is not null && employees.Any() ? employees : new();
64-
return Task.CompletedTask;
65-
}
66-
6759
public record class Employee
6860
{
6961
public int Id { get; set; }

docs/docs/05-components/grid.mdx

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ Grid requires either `Data` or `DataProvider` parameter, but not both.
101101
| SortKeySelector | `Expression<Func<TItem, IComparable>>` | | | Expression used for sorting. | 1.0.0 |
102102
| SortString | string | null | | Gets or sets the column sort string. This string is passed to the backend/API for sorting. And it is ignored for client-side sorting. | 1.0.0 |
103103
| StringComparison | `StringComparison` | `StringComparison.OrdinalIgnoreCase` | | Gets or sets the StringComparison. Use `StringComparison.CurrentCulture` or `StringComparison.CurrentCultureIgnoreCase` or `StringComparison.InvariantCulture` or `StringComparison.InvariantCultureIgnoreCase` or `StringComparison.Ordinal` or `StringComparison.OrdinalIgnoreCase`. | 1.0.0 |
104+
| SummaryType | `GridSummaryColumnType` | `GridSummaryColumnType.None` | | Gets or sets the summary type. Supported values are `GridSummaryColumnType.None`, `GridSummaryColumnType.Count`, `GridSummaryColumnType.Sum`, `GridSummaryColumnType.Average`, `GridSummaryColumnType.Min`, `GridSummaryColumnType.Max`. | 3.4.0 |
105+
| SummaryValueDisplayFormat | string | null | | Gets or sets the summary value display format. | 3.4.0 |
104106
| TextAlignment | `Alignment` | `Alignment.Start` | | Gets or sets the text alignment. Use `Alignment.Start` or `Alignment.Center` or `Alignment.End`. | 1.0.0 |
105107
| TextNoWrap | bool | false | | Gets or sets text nowrap. | 1.0.0 |
106108
| IsVisible | bool | true | | Gets or sets visibility of the Grid column. | 3.4.0 |
@@ -4187,4 +4189,86 @@ Set the <code>IsVisible</code> parameter to **false** to hide the column.
41874189
}
41884190
```
41894191

4190-
[See demo here](https://demos.blazorbootstrap.com/grid/other#hide-columns)
4192+
[See demo here](https://demos.blazorbootstrap.com/grid/other#hide-columns)
4193+
4194+
### Summary
4195+
4196+
To enable summaries on columns, set the `AllowSummary` parameter to **true** at the Grid level. Additionally, set the `SummaryType` parameter on each GridColumn.
4197+
In the following example, the Employee Name column has `SummaryType` set to **GridSummaryColumnType.Count**, and the **Salary** column has `SummaryType` set to **GridSummaryColumnType.Sum** and `SummaryValueDisplayFormat` set to **C** to display the sum of salaries in currency format.
4198+
4199+
<img src="https://i.imgur.com/1DHiEkN.png" alt="Blazor Bootstrap: Grid Component - Summary" />
4200+
4201+
```cshtml {} showLineNumbers
4202+
<Grid TItem="Employee"
4203+
Class="table table-hover table-bordered table-striped"
4204+
DataProvider="EmployeesDataProvider"
4205+
AllowSummary="true"
4206+
Responsive="true">
4207+
4208+
<GridColumns>
4209+
<GridColumn TItem="Employee" HeaderText="Id" PropertyName="Id">
4210+
@context.Id
4211+
</GridColumn>
4212+
<GridColumn TItem="Employee" HeaderText="Employee Name" PropertyName="Name" SummaryType="GridSummaryColumnType.Count">
4213+
@context.Name
4214+
</GridColumn>
4215+
<GridColumn TItem="Employee" HeaderText="Designation" PropertyName="Designation">
4216+
@context.Designation
4217+
</GridColumn>
4218+
<GridColumn TItem="Employee" HeaderText="DOJ" PropertyName="DOJ">
4219+
@context.DOJ
4220+
</GridColumn>
4221+
<GridColumn TItem="Employee" HeaderText="Salary" PropertyName="Salary" SummaryType="GridSummaryColumnType.Sum" SummaryValueDisplayFormat="C">
4222+
@context.Salary.ToString("C")
4223+
</GridColumn>
4224+
<GridColumn TItem="Employee" HeaderText="Active" PropertyName="IsActive">
4225+
@context.IsActive
4226+
</GridColumn>
4227+
</GridColumns>
4228+
</Grid>
4229+
```
4230+
4231+
```cshtml {} showLineNumbers
4232+
@code {
4233+
private IEnumerable<Employee> employees = default!;
4234+
4235+
private async Task<GridDataProviderResult<Employee>> EmployeesDataProvider(GridDataProviderRequest<Employee> request)
4236+
{
4237+
if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging
4238+
employees = GetEmployees(); // call a service or an API to pull the employees
4239+
4240+
return await Task.FromResult(request.ApplyTo(employees));
4241+
}
4242+
4243+
private IEnumerable<Employee> GetEmployees()
4244+
{
4245+
return new List<Employee>
4246+
{
4247+
new Employee { Id = 107, Name = "Alice", Designation = "AI Engineer", DOJ = new DateOnly(1998, 11, 17), Salary = 7700, IsActive = true },
4248+
new Employee { Id = 103, Name = "Bob", Designation = "Senior DevOps Engineer", DOJ = new DateOnly(1985, 1, 5), Salary = 19000, IsActive = true },
4249+
new Employee { Id = 106, Name = "John", Designation = "Data Engineer", DOJ = new DateOnly(1995, 4, 17), Salary = 12000, IsActive = true },
4250+
new Employee { Id = 104, Name = "Pop", Designation = "Associate Architect", DOJ = new DateOnly(1985, 6, 8), Salary = 19000, IsActive = false },
4251+
new Employee { Id = 105, Name = "Ronald", Designation = "Senior Data Engineer", DOJ = new DateOnly(1991, 8, 23), Salary = 16500.50f, IsActive = true },
4252+
new Employee { Id = 102, Name = "Line", Designation = "Architect", DOJ = new DateOnly(1977, 1, 12), Salary = 24000, IsActive = true },
4253+
new Employee { Id = 101, Name = "Daniel", Designation = "Architect", DOJ = new DateOnly(1977, 1, 12), Salary = 21000, IsActive = true },
4254+
new Employee { Id = 113, Name = "Merlin", Designation = "Senior Consultant", DOJ = new DateOnly(1989, 10, 2), Salary = 13500, IsActive = true },
4255+
new Employee { Id = 117, Name = "Sharna", Designation = "Data Analyst", DOJ = new DateOnly(1994, 5, 12), Salary = 15800.10f, IsActive = true },
4256+
new Employee { Id = 108, Name = "Zayne", Designation = "Data Analyst", DOJ = new DateOnly(1991, 1, 1), Salary = 14000, IsActive = true },
4257+
new Employee { Id = 109, Name = "Isha", Designation = "App Maker", DOJ = new DateOnly(1996, 7, 1), Salary = 8000, IsActive = true },
4258+
new Employee { Id = 111, Name = "Glenda", Designation = "Data Engineer", DOJ = new DateOnly(1994, 1, 12), Salary = 17850, IsActive = true },
4259+
};
4260+
}
4261+
4262+
public record class Employee
4263+
{
4264+
public int Id { get; set; }
4265+
public string? Name { get; set; }
4266+
public string? Designation { get; set; }
4267+
public DateOnly DOJ { get; set; }
4268+
public float Salary { get; set; }
4269+
public bool IsActive { get; set; }
4270+
}
4271+
}
4272+
```
4273+
4274+
[See demo here](https://demos.blazorbootstrap.com/grid/summary)

0 commit comments

Comments
 (0)