Skip to main content
August 7, 2024
Question

Create dynamic columns for the gridField based on the data.

  • August 7, 2024
  • 6 replies
  • 0 views

Hello,

I am new to Appian and have a requirement to create grid columns dynamically based on the data available in the database. I need to generate these columns dynamically according to the available data.

Thank You..!!

6 replies

prasantap0900
August 7, 2024

Query the data, Store the data in a local variable, use that local variable as grid data.

Else you can use the record as a grid data directly. 

August 7, 2024

Hello [mention:06d3c31e5c9d4c979813e345053c3afc:e9ed411860ed4f2ba0265705b8793d05] 

Thanks for the reply.

I have already fetched the data into the local variable like this:

local!networkData: index( rule!MWM_QRD_getNetworktData(networkId: 1), "data", {} ),

How can I use this data in a grid directly with foreach?

prasantap0900
August 7, 2024

a!gridField(
      label: "",
      labelPosition: "ABOVE",
      data: local!name,
      columns: {
        a!gridColumn(
          label: "First Name",
          sortField: local!name['recordType!GT CustomerDetails.fields.firstName'],
          value: fv!row['recordType!GT CustomerDetails.fields.firstName']
        ),
        a!gridColumn(
          label: "Last Name",
          sortField: local!name['recordType!GT CustomerDetails.fields.lastName'],
          value: fv!row['recordType!GT CustomerDetails.fields.lastName']
        )
      },
      pageSize: 16
    )
  }
)

August 7, 2024

Here, I want the columns to be displayed dynamically. If there are 10 data fields, then 10 columns should be displayed dynamically.

August 7, 2024

The following code might be helpful:

= a!localVariables(
  local!CDTFields: split(
    stripwith(
      tostring(
        'type!{urn:com:appian:types:YD}YD_DEMO123'()
      ),
      "=[] "
    ),
    ","
  ),
  local!cdtData: a!queryEntity(
    entity: cons!YD_DT_DEMO123,
    query: a!query(
      pagingInfo: a!pagingInfo(startIndex: 1, batchSize: - 1)
    ),
    fetchTotalCount: false
  ),
  {
    a!gridField(
      data: local!cdtData.data,
      columns: a!forEach(
        items: local!CDTFields,
        expression: a!gridColumn(
          label: fv!item,
          value: index(fv!row, fv!item),
          align: "END"
        )
      )
    )
  }
)

You have to replace CDT name in the above code.