@if (totalCount > 0) { @for (int i = @startPage; i <= endPage; ++i) { var pageNum = i; @pageNum } }
@totalCount records
@if (totalCount > 0) {
row/pag: 
}
@code { void HandlePaginationItemClick(string page) { currPage = int.Parse(page); reportChangePage(); } private int numPages { get; set; } = 10; // calcola un set 1..numPOages centrato sulla pagina corrente... private int startPage { get { int answ = (int)(currPage / numPages) * numPages - 2; answ = answ > 0 ? answ : 1; return answ; } } private int endPage { get { int answ = (int)(currPage / numPages) * numPages + numPages + 2; answ = answ < LastPage ? answ : LastPage; return answ; } } 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 PageSize { get { return _numRecord; } set { bool doReport = !_numRecord.Equals(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 numRecordChanged { get; set; } [Parameter] public EventCallback numPageChanged { get; set; } private void reportChange() { numRecordChanged.InvokeAsync(PageSize); } private void reportChangePage() { numPageChanged.InvokeAsync(currPage); } }