Skip to main content
November 11, 2022
Question

pagination in layout grid without using foreach

  • November 11, 2022
  • 4 replies
  • 0 views

how can we achive pagination in layout grid without using foreach?.

4 replies

November 11, 2022

Maybe you can try this?

if(
  or(
    ri!totalCount = 0,
    a!isNullOrEmpty(ri!totalCount)
  ),
  {},
  a!richTextDisplayField(
    align: "RIGHT",
    value: {
      a!richTextIcon(
        icon: "angle-double-left",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: { a!save(ri!pagingInfo.startIndex, 1) },
          showWhen: not(ri!pagingInfo.startIndex <= 1)
        ),
        color: if(
          ri!pagingInfo.startIndex <> 1,
          "STANDARD",
          "SECONDARY"
        ),
        linkStyle: "STANDALONE"
      ),
      a!richTextIcon(
        icon: "angle-left",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: {
            a!save(
              ri!pagingInfo.startIndex,
              ri!pagingInfo.startIndex - ri!pagingInfo.batchSize
            )
          },
          showWhen: not(ri!pagingInfo.startIndex <= 1)
        ),
        color: if(
          ri!pagingInfo.startIndex <> 1,
          "STANDARD",
          "SECONDARY"
        ),
        linkStyle: "STANDALONE"
      ),
      " ",
      a!richTextItem(
        text: {
          if(
            ri!totalCount > 0,
            { ri!pagingInfo.startIndex, "-" },
            ""
          ),
          if(
            ri!pagingInfo.startIndex + ri!pagingInfo.batchSize - 1 > ri!totalCount,
            ri!totalCount,
            ri!pagingInfo.startIndex + ri!pagingInfo.batchSize - 1
          )
        },
        size: "MEDIUM",
        style: "STRONG",
        
      ),
      a!richTextItem(
        text: {
          if(ri!totalCount > 0, " of ", ""),
          ri!totalCount
        },
        size: "MEDIUM"
      ),
      a!richTextIcon(
        icon: "angle-right",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: {
            a!save(
              ri!pagingInfo.startIndex,
              ri!pagingInfo.startIndex + ri!pagingInfo.batchSize
            )
          },
          showWhen: ri!totalCount >= ri!pagingInfo.startIndex + ri!pagingInfo.batchSize
        ),
        color: if(
          ri!pagingInfo.startIndex > (ri!totalCount - ri!pagingInfo.batchSize),
          "SECONDARY",
          "STANDARD"
        ),
        linkStyle: "STANDALONE"
      ),
      a!richTextIcon(
        icon: "angle-double-right",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: {
            a!save(
              ri!pagingInfo.startIndex,
              if(
                mod(ri!totalCount, ri!pagingInfo.batchSize) = 0,
                ri!totalCount - (ri!pagingInfo.batchSize) + 1,
                (
                  floor(ri!totalCount / ri!pagingInfo.batchSize) * ri!pagingInfo.batchSize
                ) + 1
              )
            )
          },
          showWhen: ri!totalCount >= ri!pagingInfo.startIndex + ri!pagingInfo.batchSize
        ),
        color: if(
          ri!pagingInfo.startIndex > (ri!totalCount - ri!pagingInfo.batchSize),
          "SECONDARY",
          "STANDARD"
        ),
        linkStyle: "STANDALONE"
      )
    }
  )
)

gopalk2865
November 11, 2022

Hi, are you trying to implement pagination in grid layout?

stefanhelzle0001
November 11, 2022

For me, pagination has no connection to a foreach. Would you mind going into more detail?

In this forum, we trade tips for details :-)

mikes0011
Brainy
November 11, 2022

My general recommendation: don't.

Further: if you want good advice here, tell us more about your use case and allow us to help you figure out solutions to your requirement, instead of figuring out how to reinvent the wheel or "build a better horse".

The problem is, paging among a data set where you're making active / unsaved changes opens up exponential avenues for accidentally losing / overwriting unsaved changes.  My rule of thumb is if you need to ask about it here, you're not experienced enough to handle the implementation.  Even I avoid this particular implementation because of how big of a chore it is to build, handle corner cases, then maintain in the future.  In other words, there are at least a dozen better ways that use non-bespoke functionality.