/// <summary>
        /// Instructs the component to show the specified page.
        /// </summary>
        /// <param name="criteria">Details of the page to be displayed.</param>
        public async Task PageAsync(PageCriteria criteria)
        {
            SetPageCriteria(criteria);
            await GetDataAsync().ConfigureAwait(true);

            await PageChanged.InvokeAsync(criteria).ConfigureAwait(true);
        }
        protected async Task OnPaginationItemClick(string pageName)
        {
            if (int.TryParse(pageName, out var pageNumber))
            {
                CurrentPage = pageNumber;
            }
            else
            {
                if (pageName == "prev")
                {
                    CurrentPage--;

                    if (CurrentPage < 1)
                    {
                        CurrentPage = 1;
                    }
                }
                else if (pageName == "next")
                {
                    CurrentPage++;

                    if (CurrentPage > LastPage)
                    {
                        CurrentPage = LastPage;
                    }
                }
            }

            await PageChanged.InvokeAsync(new DataGridPageChangedEventArgs( CurrentPage, PageSize ));

            if (ReadData.HasDelegate)
            {
                await HandleReadData();
            }
        }
Beispiel #3
0
        protected void FetchBatch(int batchIndex)
        {
            if (_provider == null)
            {
                return;
            }

            _isFetching = true;

            if (_tokenSource != null)
            {
                _tokenSource.Cancel();
            }

            _tokenSource = new CancellationTokenSource();

            Task.Run(
                async() =>
            {
                var tokenSource = _tokenSource;

                try
                {
                    var batch = await _provider.FetchAsync(batchIndex, ItemsPerPage, tokenSource.Token);

                    if (!tokenSource.IsCancellationRequested)
                    {
                        var previousPage = _page;

                        _page       = batchIndex;
                        _totalItems = batch.Total;
                        _totalPages = (int)Math.Ceiling((double)batch.Total / ItemsPerPage);
                        _items      = batch.Items;

                        // Check whether we changed the page or just reloaded it
                        if (_page != previousPage)
                        {
                            await PageChanged.InvokeAsync(batchIndex);
                        }

                        StateHasChanged();
                    }
                }
                catch (Exception ex)
                {
                    _errorMessage    = "Items couldn't be fetched";
                    _showRetryButton = true;

                    ConsoleHelper.WriteExceptionFromComponent(ex, typeof(LxPaging <>));
                }
                finally
                {
                    tokenSource.Dispose();

                    if (_tokenSource == tokenSource)
                    {
                        _isFetching  = false;
                        _tokenSource = null;

                        StateHasChanged();
                    }
                }
            });
        }
 protected async Task OnPageClick(string uri, int page)
 {
     UriHelper.NavigateTo(uri, false);
     await PageChanged.InvokeAsync(page);
 }