Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (91 sloc) 4.1 KB
@page "/datagrid-footer-totals"
@using NorthwindBlazor.Data
@using NorthwindBlazor.Models.Northwind
@using Microsoft.EntityFrameworkCore
@inject NorthwindContext dbContext
<h1 style="display:inline">DataGrid Footer Totals</h1><a style="margin-left: 10px" href="https://github.com/akorchev/blazor.radzen.com/blob/master/Pages/DataGridFooterTotals.razor" target="_blank">[source code]</a><a style="margin-left: 10px" href="https://www.radzen.com/documentation/blazor/datagrid/" target="_blank">[documentation]</a>
<p>This page demonstrates fetching data from the server using <b>IQueryable</b> bound to a <b>DataGrid</b> with totals in column footers.</p>
@if (orders == null)
{
<p><em>Loading...</em></p>
}
else
{
<div class="row">
<div class="col-md-12">
<RadzenGrid @ref="ordersGrid" AllowFiltering="true" AllowPaging="true" PageSize="3" AllowSorting="true"
Data="@orders" TItem="Order" Value="@order">
<Columns>
<RadzenGridColumn Width="200px" TItem="Order" Property="OrderID" Title="Order ID">
<FooterTemplate>
Total orders: <b>@orders.Count()</b>
</FooterTemplate>
</RadzenGridColumn>
<RadzenGridColumn Width="200px" TItem="Order" Property="Customer.CompanyName" Title="Customer" />
<RadzenGridColumn TItem="Order" Property="Employee.LastName" Title="Employee">
<Template Context="order">
<div>@order.Employee?.LastName</div>
<RadzenImage Path="@order.Employee?.Photo" Style="width:150px" />
</Template>
</RadzenGridColumn>
<RadzenGridColumn TItem="Order" Property="OrderDate" Title="Order Date">
<Template Context="order">
@String.Format("{0:d}", order.OrderDate)
</Template>
<FooterTemplate>
Last order date: <b>@String.Format("{0:d}", orders.OrderByDescending(o => o.OrderDate).Last().OrderDate)</b>
</FooterTemplate>
</RadzenGridColumn>
<RadzenGridColumn TItem="Order" Property="Freight" Title="Freight">
<Template Context="order">
@String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", order.Freight)
</Template>
<FooterTemplate>
Total amount: <b>@String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", orders.Sum(o => o.Freight))</b>
</FooterTemplate>
</RadzenGridColumn>
<RadzenGridColumn TItem="Order" Property="ShipName" Title="Ship Name" />
</Columns>
</RadzenGrid>
</div>
</div>
}
@code {
RadzenGrid<Order> ordersGrid;
Order order;
IEnumerable<Order> orders;
IEnumerable<Customer> customers;
protected override async Task OnInitializedAsync()
{
customers = await Task.FromResult(dbContext.Customers);
orders = await Task.FromResult(from order in dbContext.Orders
.Include("Customer")
.Include("Employee")
.Include("OrderDetails")
.Include("OrderDetails.Product")
select order);
order = orders.FirstOrDefault();
}
void EditRow(Order order)
{
ordersGrid.EditRow(order);
}
void UpdateRow(Order order)
{
ordersGrid.UpdateRow(order);
dbContext.Update<Order>(order);
dbContext.SaveChanges();
}
void CancelEdit(Order order)
{
ordersGrid.CancelEditRow(order);
var orderEntry = dbContext.Entry(order);
orderEntry.CurrentValues.SetValues(orderEntry.OriginalValues);
orderEntry.State = EntityState.Unchanged;
}
void DeleteRow(Order order)
{
dbContext.Remove<Order>(order);
dbContext.SaveChanges();
}
}
You can’t perform that action at this time.