You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
using Blazorise;
|
|
using Blazorise.DataGrid;
|
|
using HeartTrack.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Localization;
|
|
using System.Collections.Generic;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace HeartTrack.Pages
|
|
{
|
|
public partial class Tokens
|
|
{
|
|
private List<User> users;
|
|
|
|
private int totalUser;
|
|
|
|
[Inject]
|
|
public HttpClient Http { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
[Inject]
|
|
public IStringLocalizer<Tokens> Localizer { get; set; }
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
|
|
{
|
|
if (e.CancellationToken.IsCancellationRequested)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// When you use a real API, we use this follow code
|
|
//var response = await Http.GetJsonAsync<Item[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
|
|
var response = (await Http.GetFromJsonAsync<User[]>($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
{
|
|
totalUser = (await Http.GetFromJsonAsync<List<User>>($"{NavigationManager.BaseUri}fake-data.json")).Count;
|
|
users = new List<User>(response); // an actual data for the current page
|
|
}
|
|
}
|
|
}
|
|
}
|