Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • DonZalmrol 220 posts 833 karma points
    Jun 24, 2015 @ 15:09
    DonZalmrol
    0

    Pagination on site

    Hi all,

    I'm searching for a good, fast and easy way to implement a pagination on my sites. As an example you can see on my test site two test projects.

    http://brouwerij.gregoir.be/bieren/

    How can I say like I only wan't to have 1 item per page and not more? If you want to scroll through the rest, you need to use the buttons below (older and newer).

    I've searched the web and forum and come across a few options, but none seems to work on my site...

    Could anybody help me?

    Thanks!

    Laurens

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 24, 2015 @ 16:03
    Dave Woestenborghs
    0

    Hi Laurens,

    Can you maybe post the code you have right now. Then we can start from there.

    Dave

  • DonZalmrol 220 posts 833 karma points
    Jun 24, 2015 @ 17:25
    DonZalmrol
    0

    Hi Dave,

    I've used this as a starting point. https://our.umbraco.org/forum/developers/razor/41166-Razor-Paging-snippet

    I know that I need to change the .IsDocumentType("xxxxx") to my page name. I did that, but nothing is working...

    @inherits UmbracoTemplatePage
    

    @{Layout = "MasterTemplate.cshtml";} @{ var pageSize = 3; var page = 1; int.TryParse(Request.QueryString["p"], out page); var items = Model.Content.Children().Where(x => x.IsDocumentType("BlogPost")).OrderByDescending(x => x.CreateDate); var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);

    if (page > totalPages)
    {
        page = totalPages;
    }
    else if (page < 1)
    {
        page = 1;
    }
    

    }

    @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)) { } @if (totalPages > 1) {
      @if (page > 1) {
    • Prev
    • } @for (int p = 1; p < totalPages + 1; p++) { var active = (p == page) ? "active" : string.Empty;
    • 1
    • } @if (page < items.Count()) {
    • Next
    • }
    }
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 06:58
    Dave Woestenborghs
    0

    Code seems fine. Maybe you can change the where clause to this to see if it helps

    .Where(x => x.DocumentTypeAlias == "TheAliasOfYourDoctype")

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 07:40
    DonZalmrol
    0

    Hi Dave,

    I've tried your suggested change. However I now get an error.

    enter image description here

    So how I basically work with the partial is like this:

    Under settings:

    Templates -> Master -> Project Page I have a renderpartial that's being called upon.

    @{ Html.RenderPartial("Pagination"); }

    The partial is listed under Partial views -> Pagination and contains the code for the pagination itself.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 07:44
    Dave Woestenborghs
    0

    It looks like you implemented my code wrong.

    It should be : .Where(x => x.DocumentTypeAlias == "TheAliasOfYourDoctype")

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 07:55
    DonZalmrol
    0

    Oh my mistake. Apologies.

    I've changed it and now I don't have an error anymore. But it still isn't working I'm afraid..

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 07:57
    Dave Woestenborghs
    0

    Maybe stupid question. But how many items do you have ? I only see 2, but you set your page size to 3. Try setting it to 1.

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 08:17
    DonZalmrol
    0

    I've created 5 more test pages (so now 7 in total) and changed the pagesize to 1 for testing. The pagenation field is still empty.

    It's like it's looking in the wrong section and can't find anything to list.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 08:28
    Dave Woestenborghs
    0

    Can you try to out put the values from page totalpage

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 08:32
    DonZalmrol
    0

    Hmm, if you now go to http://brouwerij.gregoir.be/bieren/ you will see the result of the requested.

    Seems it has a problem with the items.

    items = System.Linq.OrderedEnumerable`2[Umbraco.Core.Models.IPublishedContent,System.DateTime]

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 08:34
    Dave Woestenborghs
    0

    Can you add .ToList() add the end of this line where you get the items ?

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 08:36
    DonZalmrol
    0

    Still the same error.

    items = @items.ToList()

    items = System.Collections.Generic.List`1[Umbraco.Core.Models.IPublishedContent]

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 08:38
    Dave Woestenborghs
    0

    It seems that there is something wrong with the calculation of total pages. It says it's 0

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 08:40
    DonZalmrol
    0

    I think there is an issue in the code to fetch the page.

    var items = Model.Content.Children().Where(x => x.DocumentTypeAlias == "ProjectPage").OrderByDescending(x => x.CreateDate).ToList();

    That's why it can't count the total pages and shows 0.

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 08:46
    DonZalmrol
    0

    Okay, seems that this is working:

    var items = CurrentPage.Site().FirstChild("ProjectPage").Children.Where("Visible");

    But, I have some other issues now with the pagenation. It doens't show the page number correctly. (they are all 1 instead of 1, 2, 3, 4) and the browsing doesn't work.

    Nor does my previous button shows :p

    But we are getting there :)

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 09:11
    DonZalmrol
    0

    Okay, fixed the page numbering.

    Nearly there, but my previous buttons is still missing and my content is not changing per page..

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 09:26
    Dave Woestenborghs
    0

    Can you show your code again like you have it now ?

    Dave

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 09:31
    DonZalmrol
    0

    Sure Dave,

    Here is the link to the code.

    http://pastebin.com/0FrWNZ8F

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 25, 2015 @ 09:43
    Dave Woestenborghs
    100

    I see the problem. You check on querystring parameter "p" to get the current page. While the actual querystring parameter is "page".

    So change it to this : int.TryParse(Request.QueryString["page"], out page);

    Dave

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 09:53
    DonZalmrol
    0

    That did it!

    One last thing, is it possible to hide the "next" button when it reaches the last page?

    I think so, since it works for the first page. I need to include an and state defining the last page.

    Something like this perhaps

    @if (page < items.Count() && page != items.Count() )

  • DonZalmrol 220 posts 833 karma points
    Jun 25, 2015 @ 10:06
    DonZalmrol
    0

    Found it :)

    @if (page < items.Count() && page != totalPages)

  • mani 7 posts 77 karma points notactivated
    Jan 09, 2024 @ 05:40
    mani
    0

    Hi, how to implemente pagination(need to show 50 dealer per page) in umbraco cms v7.7 please provide step by setp process because i was new to this cms

    Thank you

  • mani 7 posts 77 karma points notactivated
    Jan 09, 2024 @ 05:45
    mani
    0

    I need to remove existing one and add pagination of 50 dealers per page

    which pages are need to change also give me some knowledge

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft