Skip to main content
Participating Frequently
Jul 10, 2023 7:29 AM UTC
Solved

Question relate to array

Hi All,

I've a question relate to array.

I've a array like {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}

Want to print in row and column for mat like this:


1     2     3      4       5

6     7     8      9       10

11   12   13    14     15

16   17   18




Currently we have 18 items. It can be 25 items, 100 items, 200 items and so on...

I print all items in rich text in column layout.


    stefanhelzle0001
    Brainy
    Jul 10, 2023 10:26 AM UTC

    In this blog post

    https://appian.rocks/2022/09/19/building-customisable-components/

    I describe how to turn a list into a two-dimensional matrix. Then you can just run two nested foreach() loops to output the values in any way you like.

    12 replies

    stefanhelzle0001
    Brainy
    Jul 10, 2023 8:13 AM UTC

    Just use two nested foreach loops, just like in any other programming language. Give it a try, and we can help you in case you have a specific question.

    Participating Frequently
    Jul 10, 2023 8:19 AM UTC

    a!localVariables(
      local!array: enumerate(ri!input) + 1,
      local!cardsPerRow: 5,
      local!numOfRows: tointeger(
        ceiling(
          count(local!array) / local!cardsPerRow,
          .5
        )
      ),
     a!columnLayout(
          contents: {
            a!forEach(
              items: enumerate(local!numOfRows) + 1,
              expression: a!localVariables(
                local!rowIndex: fv!index,
                a!columnsLayout(
                  columns: a!forEach(
                    items: enumerate(local!cardsPerRow) + 1,
                    expression: a!localVariables(
                      local!colIndex: local!cardsPerRow * local!rowIndex - local!cardsPerRow + fv!index,
                      local!entityIdForColIndex: index(local!array, local!colIndex, null()),
                      a!columnLayout(
                        contents: a!richTextDisplayField(
                          value: a!richTextItem(
                            text: index(
                              local!array,
                              local!entityIdForColIndex,
                              null()
                            )
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          }
        )
      
    )


    I think the above code will work dynamically for your requirement. 

    Participating Frequently
    Jul 10, 2023 8:25 AM UTC

    type of input is integer array ?

    Participating Frequently
    Jul 10, 2023 8:29 AM UTC

    No, It is just integer.