Update DataPager con possibilità specifica PageSizeList

This commit is contained in:
Samuele Locatelli
2023-05-09 10:45:23 +02:00
parent f9f4654d97
commit eafee1619b
5 changed files with 112 additions and 33 deletions
@@ -9,7 +9,7 @@ namespace EgwCoreLib.BlazorTest.Data
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
return Task.FromResult(Enumerable.Range(1, 25).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
+1 -22
View File
@@ -36,28 +36,7 @@ else
}
</tbody>
</table>
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="SetNumRec" numPageChanged="SetCurrPage" totalCount="@totalCount" showLoading="@isLoading" PageSizeList="@PageSizeEnab" />
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
}
protected async Task ReloadAllData()
{
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
private bool sortAsc = true;
private string sortField = "";
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadAllData();
}
}
@@ -0,0 +1,70 @@
using EgwCoreLib.BlazorTest.Data;
using EgwCoreLib.Razor;
namespace EgwCoreLib.BlazorTest.Pages
{
public partial class FetchData
{
#region Protected Properties
protected List<int> PageSizeEnab { get; set; } = new List<int>();
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
PageSizeEnab = new List<int>()
{
4,8,12,16,20,24,28,32,36,40
};
await ReloadAllData();
}
protected async Task ReloadAllData()
{
var rawData = await ForecastService.GetForecastAsync(DateTime.Now);
totalCount = rawData.Count();
forecasts = rawData.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
}
protected async Task SetCurrPage(int newNum)
{
currPage = newNum;
await ReloadAllData();
}
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
await ReloadAllData();
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadAllData();
}
#endregion Protected Methods
#region Private Fields
private List<WeatherForecast>? forecasts;
private bool sortAsc = true;
private string sortField = "";
#endregion Private Fields
#region Private Properties
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 8;
private int totalCount { get; set; } = 0;
#endregion Private Properties
}
}
+4 -5
View File
@@ -53,11 +53,10 @@
{
<div class="input-group input-group-sm">
<select @bind="@PageSize" class="form-select form-select-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
@foreach (var item in PageSizeList)
{
<option value="@item">@item</option>
}
</select>
</div>
}
+36 -5
View File
@@ -6,6 +6,9 @@ namespace EgwCoreLib.Razor
{
#region Public Properties
/// <summary>
/// Num pagina correntemente selezioanta
/// </summary>
[Parameter]
public int currPage
{
@@ -24,21 +27,35 @@ namespace EgwCoreLib.Razor
}
}
/// <summary>
/// Export (csv) abilitato
/// </summary>
[Parameter]
public bool exportEnabled { get; set; } = false;
/// <summary>
/// Evento richiesta export
/// </summary>
[Parameter]
public EventCallback<int> exportRequested { get; set; }
/// <summary>
/// Filename x export
/// </summary>
[Parameter]
public string fileName { get; set; } = "";
/// <summary>
/// Evento cambio pagina nel paginatore
/// </summary>
[Parameter]
public EventCallback<int> numPageChanged { get; set; }
/// <summary>
/// PageSize = Num record da mostrare cambiato
/// </summary>
[Parameter]
public EventCallback<int> numRecordChanged { get; set; }
/// <summary>
/// Attuale PageSize
/// </summary>
[Parameter]
public int PageSize
{
@@ -57,6 +74,9 @@ namespace EgwCoreLib.Razor
}
}
/// <summary>
/// Fase di loading
/// </summary>
[Parameter]
public bool showLoading
{
@@ -78,10 +98,21 @@ namespace EgwCoreLib.Razor
_showLoading = value;
}
}
/// <summary>
/// Totale record da mostrare
/// </summary>
[Parameter]
public int totalCount { get; set; } = 0;
/// <summary>
/// Elenco dei PageSize ammessi
/// </summary>
[Parameter]
public List<int> PageSizeList { get; set; } = new List<int>()
{
5,10,25,50,100
};
#endregion Public Properties
#region Public Methods