pagination in layout grid without using foreach

Certified Senior Developer

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

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    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"
          )
        }
      )
    )

  • 0
    Certified Senior Developer

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

  • 0
    Certified Lead Developer

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

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

  • 0
    Certified Lead Developer

    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.