Open Majestijn opened 2 years ago
I can see that being confusing. FetchData
should have been declared in the example. That's a mistake that we'll have to fix.
That being said, FetchData
is just your own method for retrieving data. e.g.: in the basic Microsoft starter app for Blazor, there is usually an injected WeatherForecastService
. Here's how that might look with that service.
@inject WeatherForecastService _forecastService
// rest of code here
protected override async Task OnInitializedAsync()
{
_data = await FetchData(_filter, _page);
}
private async Task<PagedResult<WeatherForecast>> FetchData(string filter, int page)
{
return await _forecastService.GetForecastAsync(DateTime.Now, page);
}
Where the service code looks something like:
public WeatherForecastService()
{
var rng = new Random();
_summaries = new List<WeatherForecast>();
var date = DateTime.Now;
for (var i = 0; i < 48; i++)
_summaries.Add(new WeatherForecast
{ Date = date.AddDays(i), Summary = Summaries[rng.Next(Summaries.Length)], TemperatureC = rng.Next(-20, 55), });
}
public Task<PagedResult<WeatherForecast>> GetForecastAsync(DateTime startDate, int page)
{
return Task.FromResult(_summaries
.AsQueryable()
.ToPagedResult(page, 10));
}
ah I see, and what about the _ViewImports.cshtml where you have to add the @addTagHelper *,BlazorPagination. Is that important? Because I don't have that in my project
That is also dated documentation and needs to be updated,
It should be simply adding @using BlazorPagination
to the top of the page or component.
Sorry about that. We'll update the documentation accordingly to avoid that confustion.
I got it working. Very nice! Is there a way to style the pagination? Like center the content instead of justify-end? Or the colors?
I imported this package with Nuget Package Manager, Added the using directive to my page and copied the sample code. I get the following error however: 'FetchData' does not exist in the current context.
Does this only work for Blazor WebAssembly? Because I'm using Blazor Server and don't have a _ViewImports.cshtml file to add the taghelper to.