Skip to main content
March 28, 2024
Question

Representing a local variable with an array of text in a grid view

  • March 28, 2024
  • 6 replies
  • 0 views

Hello, I have a local variable that contains an array of text retrieved from an API Call as seen below:

 

a!save(local!transactionList,                             
                        {
                          id: local!Transjsondata.GetTransInfo.TransInfo.Id,
                          time: local!Transjsondata.GetTransInfo.TransInfo.Time,
                          amount: local!Transjsondata.GetTransInfo.TransInfo.Amount,
                        })

so let's assume for example that i have 5 items in my transactionlist, each with their own id, time and amount, how can I represent each item accordingly in a gridview in its own row? I tried the below implementation: 

a!gridField(
            label: "List of Transactions",
            labelPosition: "ABOVE",
            data: local!transactionList,
            
            columns: {
              a!gridColumn(
                label: "Id",
                value: fv!row.id
              ),
              a!gridColumn(
                label: "Time",
                value: fv!row.time
                
              )
            },
            validations: {},
            selectable: true
          ),

However the problem is instead of having one row for each transaction, I have only one row that stores all 5 transactions and all 5 times, how can iterate or maybe use a foreach statement in order to divide them into separate rows?

6 replies

karumurua531442
March 28, 2024

hi [mention:5ca3724eac324319b36377f6e4fb404d:e9ed411860ed4f2ba0265705b8793d05] do you want to display,  "ID", in one column and remaining, time and amount in the next column?

is it something like this ?

March 31, 2024

Yes this is almost what I am trying to do, basically I want one column for each Id, time and amount. 

davidj137213
Brainy
March 28, 2024

I assume that you are receiving the information in that format from the Api. In that case I would suggest to work with that data, in order to transform it in a dictionary, map or just use split or create an array.

Could you post the data in the format you are receiving it from the api please?

April 1, 2024

Try Using this Approach as it Will Give Clarity and Control Over What you are trying to implement.

a!gridField(
  label: "List of Transactions",
  labelPosition: "ABOVE",
  data: {
    { id: 1, time: { now(), now() + 1, now() + 2 } },
    { id: 2, time: { now(), now() + 1, now() + 2 } }
  },
  columns: {
    a!gridColumn(label: "Id", value: fv!row.id),
    a!gridColumn(label: "Time", value: a!richTextDisplayField(value: a!richTextBulletedList(items: fv!row.time)))
  },
  validations: {},
  selectable: true
),

shubhama926776
Brainy
April 1, 2024

 [mention:5ca3724eac324319b36377f6e4fb404d:e9ed411860ed4f2ba0265705b8793d05] 
You're on the right track! To display each item in your local!transactionList as a separate row in the grid view, you can leverage the a!foreach function within the data property of the a!gridField.



शुभम्