Skip to main content
September 15, 2021
Question

How to have gridLayoutHeaderCell in gridlayout ? How to create columns dynamically in a grid ?

  • September 15, 2021
  • 4 replies
  • 0 views

I am trying below code. Here, expression rule GPO_questionDetails returns a list for a given number.

a!gridLayout(
label:"program",
headerCells: {
a!forEach(
items: {"230108","230109","230110"},
expression:{
a!localVariables(
local!list: rule!GPO_questionDetails(questionID: fv!item),
a!gridLayoutHeaderCell(label: local!list.label)
)}
),
if(not(rule!APN_isTrue(ri!isReadOnly)),a!gridLayoutHeaderCell(label: ""),{})
},

Error: Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!gridLayout [line 35]: A grid component [label="program"] has an invalid value for "headerCells". "headerCells" can only be of type GridLayoutHeaderCell. Received List of GridHeaderCell at index 1.

Can some one help me to fix this ?

4 replies

selvakumark
Participating Frequently
September 15, 2021

Hi,

Using a flatten() function will help you in this case:

 headerCells: {
      a!flatten(
        a!forEach(
          items: { "230108", "230109", "230110" },
          expression: {
            a!localVariables(
              local!list: fv!item,
              a!gridLayoutHeaderCell(label: local!list)
            )
          }
        )
      )
    }

richardm900458
September 15, 2021

btw this solves the issue too ;)

richardm900458
September 15, 2021

Avoid the {} in your a!forEach expression parameter.   you are doing a "a!forEach(items:{1,2,3}, expression:{...})
just do a  "a!forEach(items:{1,2,3}, expression:...)  then it should be fine.

a!gridLayout(
    label:"program",
    headerCells: {
        a!forEach(
            items: {"230108","230109","230110"},
            expression:  a!localVariables(
                    local!list: rule!GPO_questionDetails(questionID: fv!item),
                    a!gridLayoutHeaderCell(label: local!list.label)
            )
            
        ),
        if(
            not(rule!APN_isTrue(ri!isReadOnly)),
            a!gridLayoutHeaderCell(label: ""),
            {}
        )
    }
),


September 15, 2021

Thank you so much @Richard Michaelis. It is serving my requirement.