Forum Discussion

Natkinson's avatar
Natkinson
Genius
10 months ago

Custom pagination numbers aren't lining up

I'm getting a weird issue with a custom pagination component I'm trying to build. I have two tab items that I'm using a URL parameter to switch between. For each tab I'm using Freemarker to determine which tab is displaying and then build a feed of messages based on that. With the pagination, here's my code:

 

<#if tabParam = "latest">
<#assign pageSize=settings.name.get("layout.messages_per_page_linear")?number />
<#assign pageNum=webuisupport.path.parameters.name.get("page", 1 ) />
<#assign paginationOffset=(pageNum - 1) * pageSize />
        <#include "forum_feed_macro" />
        <#assign msgCountQry=rest("2.0","/search?q=" + "SELECT count(*) FROM messages WHERE board.id='${currentBoard}' AND depth=0"?url).data.count />

        <#assign res = liql(rest_20, "SELECT ${querySelect} FROM messages where board.id = '${currentBoard}' AND depth=0 ORDER BY post_time desc LIMIT ${pageSize} OFFSET ${paginationOffset}") />
        <@renderListResponse type="message" response=res render=messageRenderFullMessage />
        <#assign pageable_item=webuisupport.paging.pageableItem.setCurrentPageNumber(pageNum).setItemsPerPage(pageSize).setTotalItems(msgCountQry?number).setPagingMode("enumerated").build />
        <@component id="common.widget.pager" pageableItem=pageable_item />
</#if>


<#if tabParam = "activity">
<#assign pageSize=settings.name.get("layout.messages_per_page_linear")?number />
<#assign pageNum=webuisupport.path.parameters.name.get("page", 1 ) />

<#assign paginationOffset=(pageNum - 1) * pageSize />
        <#include "forum_feed_macro" />
        <#assign msgCountQryAll=rest("2.0","/search?q=" + "SELECT count(*) FROM messages WHERE board.id='${currentBoard}'"?url).data.count />
        <#assign res = liql(rest_20, "SELECT ${querySelect} FROM messages where board.id = '${currentBoard}' ORDER BY post_time desc LIMIT ${pageSize} OFFSET ${paginationOffset}") />
        <@renderListResponse type="message" response=res render=messageRenderFullMessage />
        <#assign pageable_item=webuisupport.paging.pageableItem.setCurrentPageNumber(pageNum).setItemsPerPage(pageSize).setTotalItems(msgCountQryAll?number).setPagingMode("enumerated").build />
        <@component id="common.widget.pager" pageableItem=pageable_item />
</#if>

 

My problem here is that the feed created within the second "if" statement, the pagination stops at page 8, even though it's displaying up to 25 pages available. The first section, however, does stop at page 8. I'm wondering if somehow something is getting crossed between the first and second sections. 

For reference, the variables in the second feed are as follows:

  • "pageSize" = 4
  • msgCountQryAll = 98

I just don't understand what's going on with my code that's causing the pagination in the second section to get stuck at page 8 even though it's showing up to 25 pages in the pagination component.

  • MattV's avatar
    MattV
    Khoros Staff

    Use a page parameter name other than "page".

    What's happening is the platform also uses that 'page' parameter, and will calculate the maximum page based on the settings for that node. 

    I do see you're using layout.messages_per_page_linear for your page size, but I'm guessing that the core behavior for that page isn't using that setting, and instead using something else. And that other setting is probably set to 10. Thus you're getting limited to 8 pages.

    Changing the parameter name will prove this out. If that works, you can keep it, or track the setting down that that page is using, and change it to 4.

  • Tried a modified version of this changing the parameter and the pagination is still sending me to page 7, but now the pagination component isn't updating (it's stuck on displaying page 1) and it never progresses to further pages even though the URL changes

     

    <#elseif tabParam = "activity">
    <#assign pageSize=5 />
    <#assign pageNum=webuisupport.path.rawParameters.name.get("items", "1") />
    
    <#assign paginationOffset=(pageNum?number - 1) * 5 />
            <#include "forum_feed_macro" />
            <#assign msgCountQryAll=rest("2.0","/search?q=" + "SELECT count(*) FROM messages WHERE board.id='${currentBoard}'"?url).data.count />
            <#assign res = liql(rest_20, "SELECT ${querySelect} FROM messages where board.id = '${currentBoard}' ORDER BY post_time desc LIMIT ${pageSize} OFFSET ${paginationOffset}") />
            <@renderListResponse type="message" response=res render=messageRenderFullMessage />
            <#assign pageable_item=webuisupport.paging.pageableItem.setCurrentPageNumber(pageNum?number).setItemsPerPage(5).setTotalItems(msgCountQryAll?number).setPagingMode("enumerated").build />
            <@component id="common.widget.pager" pageableItem=pageable_item />
    </#if>

    I don't understand how to make this work correctly. I understand why "page" as a parameter doesn't work, but don't understand how to implement an alternative

  • MattV what other parameter can I use besides page? When I try something like

    <#assign pageNum=webuisupport.path.parameters.name.get("items", 1 ) /> I get an ugly FreeMarker error. Or how do I use something besides "page"?
    • MattV's avatar
      MattV
      Khoros Staff

      I wouldn't expect a freemarker error... you should be able to choose whatever string you want.

      What's the exact FM error?

      • Natkinson's avatar
        Natkinson
        Genius

        I think the error was related to 1 vs "1" as the default parameter value. The latest code I posted above is no longer giving an error but is definitely not functioning properly.

  • Akenefick I've never had an issue using this either and I've used it in dozens of custom components. However, this is the first time I've used it to display different feeds using an if statement and the first time I've used it on a ForumPage quilt, so I wonder if one of those is causing the issue here.

    "rest_20" is just a variable pulling in from a macro I'm using to build out the message feeds. It just declares the api version, in this case "2.0".

  • I don't think the if statement is the problem. I did it the same way. I had 5 tabs each inside its own if block which worked off a URL parameter and did this on a custom forum page as well. Sorry I'm baffled.

    What happens when you go past page 8? Do you still have the out of the box message list or paging component on the page?

  • Akenefick yeah in testing more I'm sure the if statements aren't the problem either. There just seems to be something overriding either the total items or total pages fed to the pagination component but I can't seem to find what is overriding it. If I click anything beyond page 8 it just refreshes the page back to page 8, despite the pagination component showing pages beyond page 8. Incidentally, the first if statement section in my first code example above (where tabParam = "latest"), that content ends at page 8 and works correctly. It's almost like the pagination for the second, longer section is retaining some data from the first section, but I can't figure out if that's the case or why that would be happening