Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/PagedList.Mvc/HtmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ private static TagBuilder ItemSliceAndTotalText(IPagedList list, PagedListRender
return WrapInListItem(text, options, "PagedList-pageCountAndLocation", "disabled");
}

private static TagBuilder Ellipses(PagedListRenderOptions options)
{
var a = new TagBuilder("a")
{
InnerHtml = options.EllipsesFormat
};
private static TagBuilder Ellipses(PagedListRenderOptions options, Func<int, string> generatePageUrl, int targetPageNumber)
{
var a = new TagBuilder("a")
{
InnerHtml = options.EllipsesFormat
};

return WrapInListItem(a, options, "PagedList-ellipses", "disabled");
}
if (options.EnableEllipsesNavigation)
a.Attributes["href"] = generatePageUrl(targetPageNumber);

return WrapInListItem(a, options, "PagedList-ellipses", options.EnableEllipsesNavigation ? null : "disabled");
}

///<summary>
/// Displays a configurable paging control for instances of PagedList.
Expand Down Expand Up @@ -202,7 +205,7 @@ public static MvcHtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html,
{
//if there are previous page numbers not displayed, show an ellipsis
if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && firstPageToDisplay > 1)
listItemLinks.Add(Ellipses(options));
listItemLinks.Add(Ellipses(options, generatePageUrl, firstPageToDisplay - 1));

foreach (var i in Enumerable.Range(firstPageToDisplay, pageNumbersToDisplay))
{
Expand All @@ -216,7 +219,7 @@ public static MvcHtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html,

//if there are subsequent page numbers not displayed, show an ellipsis
if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && (firstPageToDisplay + pageNumbersToDisplay - 1) < list.PageCount)
listItemLinks.Add(Ellipses(options));
listItemLinks.Add(Ellipses(options, generatePageUrl, (firstPageToDisplay + pageNumbersToDisplay)));
}

//next
Expand Down
6 changes: 6 additions & 0 deletions src/PagedList.Mvc/PagedListRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public PagedListRenderOptions()
ContainerDivClasses = new [] { "pagination-container" };
UlElementClasses = new[] { "pagination" };
LiElementClasses = Enumerable.Empty<string>();
EnableEllipsesNavigation = false;
}

///<summary>
Expand Down Expand Up @@ -204,6 +205,11 @@ public PagedListRenderOptions()
/// An extension point which allows you to fully customize the anchor tags used for clickable pages, as well as navigation features such as Next, Last, etc.
/// </summary>
public Func<TagBuilder, TagBuilder, TagBuilder> FunctionToTransformEachPageLink { get; set; }

/// <summary>
/// Enables or disables the navigation functionality of the ellipses
/// </summary>
public bool EnableEllipsesNavigation { get; set; }

/// <summary>
/// Enables ASP.NET MVC's unobtrusive AJAX feature. An XHR request will retrieve HTML from the clicked page and replace the innerHtml of the provided element ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

<h2>Custom Pager Configurations</h2>

<h3>Functional Ellipses</h3>
@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), new PagedListRenderOptions() { EnableEllipsesNavigation = true })

<h3>Custom Wording (<em>Spanish Translation Example</em>)</h3>
@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), new PagedListRenderOptions { LinkToFirstPageFormat = "<< Primera", LinkToPreviousPageFormat = "< Anterior", LinkToNextPageFormat = "Siguiente >", LinkToLastPageFormat = "Última >>" })

Expand Down