Пример #1
0
 public void NavigateToPage(PaginationAction direction)
 {
     if (direction == PaginationAction.Next)
     {
         if (CurPage < PagesCount)
         {
             if (CurPage == EndPage)
             {
                 SetPagerSize(PaginationAction.Forward);
             }
             CurPage += 1;
         }
     }
     else if (direction == PaginationAction.Previous)
     {
         if (CurPage > 1)
         {
             if (CurPage == StartPage)
             {
                 SetPagerSize(PaginationAction.Back);
             }
             CurPage -= 1;
         }
     }
     UpdateList(CurPage);
 }
Пример #2
0
        public string GetUrl(UrlHelper urlHelper, PaginationAction action, int page = 0)
        {
            var baseUrl = this.Link.GetUrl(urlHelper);
            var delim   = baseUrl.Contains('?') ? '&' : '?';

            if (action != PaginationAction.Page)
            {
                page = Math.Min(this.MaxPages, Math.Max(0, (this.CurrentPage + (action == PaginationAction.Next ? +1 : -1))));
            }

            return(string.Format("{0}{1}o={2}&c={3}", baseUrl, delim, page * this.Count, this.Count));
        }
        private void Navigate(PaginationAction paginationAction)
        {
            switch (paginationAction)
            {
            case PaginationAction.First:
                CurrentPage = 1;
                ItemSource  = new ObservableCollection <object>(ImageFetcher.GetItemsFromDataSource(CurrentPage, PageSize, searchString));
                break;

            case PaginationAction.Last:
                CurrentPage = TotalPages;
                ItemSource  = new ObservableCollection <object>(ImageFetcher.GetItemsFromDataSource(CurrentPage, PageSize, searchString));
                break;

            case PaginationAction.Next:
                if (CurrentPage < TotalPages - 1)
                {
                    CurrentPage++;
                    ItemSource = new ObservableCollection <object>(ImageFetcher.GetItemsFromDataSource(CurrentPage, PageSize, searchString));
                }
                break;

            case PaginationAction.Previous:
                if (CurrentPage > 1)
                {
                    CurrentPage--;
                    ItemSource = new ObservableCollection <object>(ImageFetcher.GetItemsFromDataSource(CurrentPage, PageSize, searchString));
                }
                break;

            case PaginationAction.OnInit:
                CurrentPage = 1;
                int totalRecords = ImageFetcher.GetTotalRecords(searchString);

                if (totalRecords > 0)
                {
                    TotalPages = Convert.ToUInt32(totalRecords) / PageSize;
                }
                ItemSource = new ObservableCollection <object>(ImageFetcher.GetItemsFromDataSource(CurrentPage, PageSize, searchString));
                break;
            }
        }
Пример #4
0
 public void SetPagerSize(PaginationAction direction)
 {
     if (direction == PaginationAction.Forward && EndPage < PagesCount)
     {
         StartPage = EndPage + 1;
         if (EndPage + pagerSize < PagesCount)
         {
             EndPage = StartPage + pagerSize - 1;
         }
         else
         {
             EndPage = PagesCount;
         }
         StateHasChanged();
     }
     else if (direction == PaginationAction.Back && StartPage > 1)
     {
         EndPage   = StartPage - 1;
         StartPage = StartPage - pagerSize;
     }
     CurPage = StartPage;
     UpdateList(CurPage);
 }