public void PagedListData_Right() { int pageNumber = 15, pageSize = 10, pages = 20, totalCount = pageSize * pages; var data = Enumerable.Range(1, totalCount); var pagedList = data.ToPagedList(pageNumber, pageSize); var pagedListData = new PagedListData(pagedList); Assert.Equal(pageNumber, pagedListData.PageNumber); Assert.Equal(pages, pagedListData.PageCount); Assert.False(pagedListData.CanSeeFirstPage()); Assert.True(pagedListData.CanSeeLastPage()); Assert.Collection(pagedListData.PageRange, Enumerable.Range(11, TableModel.DefaultPageRange).Select(PageMatcher).ToArray()); }
public override void Process(TagHelperContext context, TagHelperOutput output) { var pageData = new PagedListData(Model.PageItems); var inputName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName("Page"); if (!pageData.CanSeeFirstPage()) { output.Content.AppendHtml(RenderPage(pageData, inputName, 1)); } foreach (var page in pageData.PageRange) { output.Content.AppendHtml(RenderPage(pageData, inputName, page)); } if (!pageData.CanSeeLastPage()) { output.Content.AppendHtml(RenderPage(pageData, inputName, pageData.PageCount)); } output.TagMode = TagMode.StartTagAndEndTag; output.TagName = "ul"; }
/// <summary> /// Renders a list with page number button elements, and a label before it /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="html"></param> /// <param name="pageData"></param> /// <param name="label"></param> /// <returns></returns> public static MvcHtmlString Pager <TModel>(this HtmlHelper <TModel> html, PagedListData pageData, string label = "Page: ") where TModel : ITableModel { var labelTag = new TagBuilder("label"); labelTag.SetInnerText(label); var ulTag = new TagBuilder("ul"); if (!pageData.CanSeeFirstPage()) { ulTag.InnerHtml += PagerLink(1); } foreach (var page in pageData.PageRange) { if (page == pageData.PageNumber) { ulTag.InnerHtml += $"<li class=\"page-current\">{page}</li>"; } else { ulTag.InnerHtml += PagerLink(page); } } if (!pageData.CanSeeLastPage()) { ulTag.InnerHtml += PagerLink(pageData.PageCount); } var divTag = new TagBuilder("div"); divTag.AddCssClass("table-pager"); divTag.InnerHtml += labelTag.ToString(); divTag.InnerHtml += ulTag; return(MvcHtmlString.Create(divTag.ToString())); }