Nuovo controllo DataPager
This commit is contained in:
@@ -1,8 +1,29 @@
|
||||
<div class="row">
|
||||
<div class="col-6 col-lg-10 text-left">
|
||||
<div class="row">
|
||||
<div class="col-9">
|
||||
paginazione
|
||||
<div class="col-9 small">
|
||||
<Pagination>
|
||||
<PaginationItem>
|
||||
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
|
||||
<span aria-hidden="true">«</span>
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
@for (int i = 1; i <= LastPage; ++i)
|
||||
{
|
||||
var pageNum = i;
|
||||
<PaginationItem Active="@(currPage.Equals(pageNum))">
|
||||
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
|
||||
@pageNum
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
}
|
||||
|
||||
<PaginationItem>
|
||||
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
|
||||
<span aria-hidden="true">»</span>
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
</Pagination>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
@totalCount records
|
||||
@@ -12,7 +33,7 @@
|
||||
<div class="col-6 col-lg-2 text-right">
|
||||
<div class="input-group input-group-sm">
|
||||
row/pag:
|
||||
<select @bind="@numRecord" class="form-control form-control-sm">
|
||||
<select @bind="@PageSize" class="form-control form-control-sm">
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
@@ -24,13 +45,29 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
void HandlePaginationItemClick(string page)
|
||||
{
|
||||
currPage = int.Parse(page);
|
||||
reportChangePage();
|
||||
}
|
||||
|
||||
private int LastPage
|
||||
{
|
||||
get
|
||||
{
|
||||
return Math.Max((int)Math.Ceiling(totalCount / (double)PageSize), 1);
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public int totalCount { get; set; } = 0;
|
||||
|
||||
protected int _numRecord { get; set; } = 10;
|
||||
protected int _numPage { get; set; } = 1;
|
||||
|
||||
[Parameter]
|
||||
public int numRecord
|
||||
public int PageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -39,20 +76,44 @@
|
||||
set
|
||||
{
|
||||
bool doReport = !_numRecord.Equals(value);
|
||||
_numRecord = value;
|
||||
if (doReport)
|
||||
{
|
||||
_numRecord = value;
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public int currPage
|
||||
{
|
||||
get
|
||||
{
|
||||
return _numPage;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = !_numPage.Equals(value);
|
||||
if (doReport)
|
||||
{
|
||||
_numPage = value;
|
||||
reportChangePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<int> numRecordChanged { get; set; }
|
||||
[Parameter]
|
||||
public EventCallback<int> numPageChanged { get; set; }
|
||||
|
||||
private void reportChange()
|
||||
{
|
||||
numRecordChanged.InvokeAsync(numRecord);
|
||||
numRecordChanged.InvokeAsync(PageSize);
|
||||
}
|
||||
private void reportChangePage()
|
||||
{
|
||||
numPageChanged.InvokeAsync(currPage);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user