|
|
|
@ -0,0 +1,71 @@ |
|
|
|
|
@page "/datagridrest" |
|
|
|
|
@using ComponentPractice.Services |
|
|
|
|
@using System.Linq.Dynamic.Core |
|
|
|
|
|
|
|
|
|
@inject NorthwindDataService service; |
|
|
|
|
|
|
|
|
|
@rendermode RenderMode.InteractiveServer |
|
|
|
|
|
|
|
|
|
<RadzenCard class="rz-p-12" Style="width: 900px"> |
|
|
|
|
<RadzenText TextStyle="TextStyle.H5">DataGrid <strong>REST</strong></RadzenText> |
|
|
|
|
<RadzenButton Text="Reset" Click="@Reset" Style="margin-bottom: 20px" /> |
|
|
|
|
|
|
|
|
|
<RadzenDataGrid @ref="grid" Data="@customers" IsLoading="@isLoading" Count="@count" LoadData="@LoadData" |
|
|
|
|
SelectionMode="DataGridSelectionMode.Single" |
|
|
|
|
AllowPaging="true" PageSize="@PAGE_SIZE" PagerHorizontalAlign="HorizontalAlign.Center" ShowPagingSummary="true" |
|
|
|
|
AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.CheckBoxList" AllowSorting="true"> |
|
|
|
|
<Columns> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.CustomerID)" Filterable="false" Title="ID" Frozen="true" Width="80px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.CompanyName)" Filterable="true" Title="Company" Frozen="true" Width="240px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.ContactTitle)" Filterable="true" Title="Contact" Width="320px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.Address)" Filterable="true" Title="Address" Width="240px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.City)" Filterable="true" Title="City" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.Region)" Filterable="true" Title="Region" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.PostalCode)" Filterable="true" Title="PostalCode" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.Country)" Filterable="true" Title="Country" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.Phone)" Filterable="true" Title="Phone" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
<RadzenDataGridColumn Property="@nameof(Customer.Fax)" Filterable="true" Title="Fax" Width="160px" TextAlign="TextAlign.Center" /> |
|
|
|
|
</Columns> |
|
|
|
|
</RadzenDataGrid> |
|
|
|
|
</RadzenCard> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@code { |
|
|
|
|
readonly int PAGE_SIZE = 10; |
|
|
|
|
|
|
|
|
|
RadzenDataGrid<Customer> grid; |
|
|
|
|
IEnumerable<Customer> customers; |
|
|
|
|
|
|
|
|
|
int count; |
|
|
|
|
bool isLoading = false; |
|
|
|
|
|
|
|
|
|
async Task Reset() |
|
|
|
|
{ |
|
|
|
|
grid.Reset(true); |
|
|
|
|
await grid.FirstPage(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async Task LoadData(LoadDataArgs args) |
|
|
|
|
{ |
|
|
|
|
isLoading = true; |
|
|
|
|
|
|
|
|
|
await Task.Yield(); |
|
|
|
|
|
|
|
|
|
var result = await service.GetCustomer(); |
|
|
|
|
|
|
|
|
|
customers = result.Value; |
|
|
|
|
var query = customers.AsQueryable(); |
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(args.Filter)) |
|
|
|
|
query = query.Where(args.Filter); |
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(args.OrderBy)) |
|
|
|
|
query = query.OrderBy(args.OrderBy); |
|
|
|
|
|
|
|
|
|
count = query.Count(); |
|
|
|
|
|
|
|
|
|
customers = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); |
|
|
|
|
|
|
|
|
|
isLoading = false; |
|
|
|
|
} |
|
|
|
|
} |