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
54 changes: 35 additions & 19 deletions src/X.PagedList.Mvc.Core/HtmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,26 @@ private TagBuilder NextEllipsis(IPagedList list, Func<int, string?> generatePage
}
}

//first
if (options.DisplayLinkToFirstPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToFirstPage == PagedListDisplayMode.IfNeeded && firstPageToDisplay > 1))
//first / previous
var firstLink = (options.DisplayLinkToFirstPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToFirstPage == PagedListDisplayMode.IfNeeded && firstPageToDisplay > 1))
? First(list, generatePageUrl, options)
: null;

var previousLink = (options.DisplayLinkToPreviousPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToPreviousPage == PagedListDisplayMode.IfNeeded && !list.IsFirstPage))
? Previous(list, generatePageUrl, options)
: null;

if (options.PlaceFirstPageAfterPreviousAndLastPageBeforeNext)
{
listItemLinks.Add(First(list, generatePageUrl, options));
if (previousLink != null) listItemLinks.Add(previousLink);
if (firstLink != null) listItemLinks.Add(firstLink);
}

//previous
if (options.DisplayLinkToPreviousPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToPreviousPage == PagedListDisplayMode.IfNeeded && !list.IsFirstPage))
else
{
listItemLinks.Add(Previous(list, generatePageUrl, options));
if (firstLink != null) listItemLinks.Add(firstLink);
if (previousLink != null) listItemLinks.Add(previousLink);
}

//text
Expand Down Expand Up @@ -463,18 +471,26 @@ private TagBuilder NextEllipsis(IPagedList list, Func<int, string?> generatePage
}
}

//next
if (options.DisplayLinkToNextPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToNextPage == PagedListDisplayMode.IfNeeded && !list.IsLastPage))
//next / last
var nextLink = (options.DisplayLinkToNextPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToNextPage == PagedListDisplayMode.IfNeeded && !list.IsLastPage))
? Next(list, generatePageUrl, options)
: null;

var lastLink = (options.DisplayLinkToLastPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToLastPage == PagedListDisplayMode.IfNeeded && lastPageToDisplay < list.PageCount))
? Last(list, generatePageUrl, options)
: null;

if (options.PlaceFirstPageAfterPreviousAndLastPageBeforeNext)
{
listItemLinks.Add(Next(list, generatePageUrl, options));
if (lastLink != null) listItemLinks.Add(lastLink);
if (nextLink != null) listItemLinks.Add(nextLink);
}

//last
if (options.DisplayLinkToLastPage == PagedListDisplayMode.Always ||
(options.DisplayLinkToLastPage == PagedListDisplayMode.IfNeeded && lastPageToDisplay < list.PageCount))
else
{
listItemLinks.Add(Last(list, generatePageUrl, options));
if (nextLink != null) listItemLinks.Add(nextLink);
if (lastLink != null) listItemLinks.Add(lastLink);
}

//text
Expand Down Expand Up @@ -588,4 +604,4 @@ public string PagedListGoToPageForm(IPagedList list, string formAction, GoToForm

return TagBuilderToString(form);
}
}
}
6 changes: 6 additions & 0 deletions src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public PagedListRenderOptions()
EllipsesElementClass = "PagedList-ellipses";
PreviousElementClass = "PagedList-skipToPrevious";
NextElementClass = "PagedList-skipToNext";
PlaceFirstPageAfterPreviousAndLastPageBeforeNext = false;
}

/// <summary>
Expand Down Expand Up @@ -95,6 +96,11 @@ public PagedListRenderOptions()
/// </summary>
public string EllipsesElementClass { get; set; }

/// <summary>
/// When true, renders the first-page link after the previous-page link and the last-page link before the next-page link.
/// </summary>
public bool PlaceFirstPageAfterPreviousAndLastPageBeforeNext { get; set; }

/// <summary>
/// Specifies a CSS class to append to the first list item in the pager. If null or whitespace is defined, no additional class is added to first list item in list.
/// </summary>
Expand Down
Loading