Skip to main content
July 10, 2023
Solved

Question relate to array

  • July 10, 2023
  • 12 replies
  • 0 views

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.


    Best answer by stefanhelzle0001

    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
    July 10, 2023

    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.

    July 10, 2023

    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. 

    July 10, 2023

    type of input is integer array ?

    July 10, 2023

    No, It is just integer.