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..!!
Discussion posts and replies are publicly visible
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.
Hello Prasanta Paul
Thanks for the reply.
I have already fetched the data into the local variable like this:
How can I use this data in a grid directly with foreach?
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 ) } )
Here, I want the columns to be displayed dynamically. If there are 10 data fields, then 10 columns should be displayed dynamically.
a!localVariables( local!items:rule!GT_firstName(), a!gridLayout( label: "Customer", headerCells: { a!gridLayoutHeaderCell(label: "First Name"), a!gridLayoutHeaderCell(label: "Gender"), }, rows: a!forEach( items: local!items, expression: { a!gridRowLayout( contents: { a!textField( value: fv!item['recordType!GT CustomerDetails.fields.firstName'], ), a!textField( value: fv!item['recordType!GT CustomerDetails.fields.gender'], ) } ) }, ) ) )
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.