From df23b4f67f60ac0b05052e7fd02886121a5103f3 Mon Sep 17 00:00:00 2001 From: Chad Bengen Date: Sat, 20 Oct 2018 08:43:49 -0700 Subject: [PATCH 1/4] fixes #121 --- .../Views/TraditionalPaging/Index.cshtml | 34 ++++++++++++++++--- src/X.PagedList.Mvc/HtmlHelper.cs | 12 ++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml index c9fe5171..ef887386 100644 --- a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml +++ b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml @@ -12,13 +12,14 @@

Example of paging a list:

-@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions {InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100}) +@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions { InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100 })

List of @ViewBag.Names.TotalItemCount Names (Page Size: @ViewBag.Names.PageSize, Current Page: @ViewBag.Names.PageNumber)

    - @foreach(var i in ViewBag.Names){ -
  1. @i
  2. - } + @foreach (var i in ViewBag.Names) + { +
  3. @i
  4. + }

Out-of-the-box Pager Configurations

@@ -55,5 +56,28 @@

Show Range of Items For Each Page

@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), new PagedListRenderOptions { FunctionToDisplayEachPageNumber = page => ((page - 1) * ViewBag.Names.PageSize + 1).ToString() + "-" + (((page - 1) * ViewBag.Names.PageSize) + ViewBag.Names.PageSize).ToString(), MaximumPageNumbersToDisplay = 5 }) +

Custom Options

+@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), + new PagedListRenderOptions + { + DisplayLinkToFirstPage = PagedListDisplayMode.Always, + DisplayLinkToLastPage = PagedListDisplayMode.Always, + DisplayLinkToNextPage = PagedListDisplayMode.Always, + DisplayLinkToPreviousPage = PagedListDisplayMode.Always, + LiElementClasses = new string[] {"page-item"}, + PageClasses = new string[] {"page-link"}, + ClassToApplyToFirstListItemInPager = "material-icons", + ClassToApplyToLastListItemInPager = "material-icons", + PreviousElementClass = "material-icons", + NextElementClass = "material-icons", + EllipsesElementClass = "material-icons", + LinkToFirstPageFormat = "first_page", + LinkToPreviousPageFormat = "chevron_left", + LinkToLastPageFormat = "last_page", + LinkToNextPageFormat = "chevron_right", + EllipsesFormat = "more_horiz" + }) +

Empty PagedList

-@Html.PagedListPager(new string[0].ToPagedList(1, 10), page => Url.Action("Index", new { page })) \ No newline at end of file +@Html.PagedListPager(new string[0].ToPagedList(1, 10), page => Url.Action("Index", new { page })) + diff --git a/src/X.PagedList.Mvc/HtmlHelper.cs b/src/X.PagedList.Mvc/HtmlHelper.cs index 07aa28e4..46719d19 100644 --- a/src/X.PagedList.Mvc/HtmlHelper.cs +++ b/src/X.PagedList.Mvc/HtmlHelper.cs @@ -358,11 +358,13 @@ private static TagBuilder PreviousEllipsis(IPagedList list, Func ge }; previous.Attributes["rel"] = "prev"; + previous.AddCssClass("PagedList-skipToPrevious"); + if (!list.HasPreviousPage) - return WrapInListItem(previous, options, "PagedList-skipToPrevious", "disabled"); + return WrapInListItem(previous, options, options.EllipsesElementClass, "disabled"); previous.Attributes["href"] = generatePageUrl(targetPageNumber); - return WrapInListItem(previous, options, "PagedList-skipToPrevious"); + return WrapInListItem(previous, options, options.EllipsesElementClass); } private static TagBuilder NextEllipsis(IPagedList list, Func generatePageUrl, PagedListRenderOptionsBase options, int lastPageToDisplay) @@ -376,11 +378,13 @@ private static TagBuilder NextEllipsis(IPagedList list, Func genera next.Attributes["rel"] = "next"; + next.AddCssClass("PagedList-skipToNext"); + if (!list.HasNextPage) - return WrapInListItem(next, options, "PagedList-skipToNext", "disabled"); + return WrapInListItem(next, options, options.EllipsesElementClass, "disabled"); next.Attributes["href"] = generatePageUrl(targetPageNumber); - return WrapInListItem(next, options, "PagedList-skipToNext"); + return WrapInListItem(next, options, options.EllipsesElementClass); } /// From b01e9895e646b968c5538744293976b070e9fd7a Mon Sep 17 00:00:00 2001 From: chadbengen Date: Sat, 20 Oct 2018 08:58:24 -0700 Subject: [PATCH 2/4] Update Index.cshtml --- .../Views/TraditionalPaging/Index.cshtml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml index ef887386..e364f2a3 100644 --- a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml +++ b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml @@ -12,14 +12,14 @@

Example of paging a list:

-@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions { InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100 }) +@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions {InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100 })

List of @ViewBag.Names.TotalItemCount Names (Page Size: @ViewBag.Names.PageSize, Current Page: @ViewBag.Names.PageNumber)

    - @foreach (var i in ViewBag.Names) - { -
  1. @i
  2. - } + @foreach (var i in ViewBag.Names) + { +
  3. @i
  4. + }

Out-of-the-box Pager Configurations

From ec00966b7c501d227d464e89ad5e2c389cb45dce Mon Sep 17 00:00:00 2001 From: chadbengen Date: Sat, 20 Oct 2018 09:00:27 -0700 Subject: [PATCH 3/4] Update Index.cshtml --- .../Views/TraditionalPaging/Index.cshtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml index e364f2a3..c354699e 100644 --- a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml +++ b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml @@ -12,11 +12,11 @@

Example of paging a list:

-@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions {InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100 }) +@Html.PagedListGoToPageForm((IPagedList)ViewBag.Names, Url.Action("Index"), new GoToFormRenderOptions {InputFieldClass = "form-control", InputWidth = 300, SubmitButtonClass = "btn", SubmitButtonWidth = 100})

List of @ViewBag.Names.TotalItemCount Names (Page Size: @ViewBag.Names.PageSize, Current Page: @ViewBag.Names.PageNumber)

    - @foreach (var i in ViewBag.Names) + @foreach(var i in ViewBag.Names) {
  1. @i
  2. } From 1a333c99d2c940ff2e374d9c926f32a0833d3a3d Mon Sep 17 00:00:00 2001 From: chadbengen Date: Sat, 20 Oct 2018 09:01:07 -0700 Subject: [PATCH 4/4] Update Index.cshtml --- .../Views/TraditionalPaging/Index.cshtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml index c354699e..73312647 100644 --- a/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml +++ b/examples/X.PagedList.Mvc.Example/Views/TraditionalPaging/Index.cshtml @@ -16,8 +16,7 @@

    List of @ViewBag.Names.TotalItemCount Names (Page Size: @ViewBag.Names.PageSize, Current Page: @ViewBag.Names.PageNumber)

      - @foreach(var i in ViewBag.Names) - { + @foreach(var i in ViewBag.Names){
    1. @i
    2. }