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.
37 lines
1.2 KiB
37 lines
1.2 KiB
using System.Net.Http.Json;
|
|
using Blazorise.DataGrid;
|
|
using BlazorProject.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace BlazorProject.Pages;
|
|
|
|
public partial class List
|
|
{
|
|
private List<Item> items;
|
|
|
|
private int totalItem;
|
|
|
|
[Inject]
|
|
public HttpClient Http { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<Item> 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<Item[]>($"{NavigationManager.BaseUri}sample-data/fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
{
|
|
totalItem = (await Http.GetFromJsonAsync<List<Item>>($"{NavigationManager.BaseUri}sample-data/fake-data.json")).Count;
|
|
items = new List<Item>(response); // an actual data for the current page
|
|
}
|
|
}
|
|
} |