display the result of a view in an editable grid

I am planning to display the result of a view in an editable grid . Can anyone please give me an example ? 

The number of rows is fixed but i dont want to write  a!gridRowLayout() 44 times as shown in the example of 2 rows

 

=load(
  local!items: {
    {item: "Item 1", qty: 1, unitPrice: 10},
    {item: "Item 2", qty: 2, unitPrice: 20}
  },
  a!gridLayout(
    label: "Grid Layout",
    instructions: "This is a grid layout",
    headerCells: {
      a!gridLayoutHeaderCell(label: "Item"),
      a!gridLayoutHeaderCell(label: "Qty", align: "RIGHT"),
      a!gridLayoutHeaderCell(label: "Unit Price", align: "RIGHT"),
      a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
    },
    rows: {
      a!gridRowLayout(
        contents: {
            a!textField(
            value: local!items[1].item,
            saveInto: local!items[1].item
          ),
          a!integerField(
            value: local!items[1].qty,
            saveInto: local!items[1].qty,
            align: "RIGHT"
          ),
          a!floatingPointField(
            value: local!items[1].unitPrice,
            saveInto: local!items[1].unitPrice,
            align: "RIGHT"
          ),
          a!textField(
            value: dollar(tointeger(local!items[1].qty) * todecimal(local!items[1].unitPrice)),
            readOnly: true,
            align: "RIGHT"
          )
        }
      ),
      a!gridRowLayout(
        contents: {
          a!textField(
            value: local!items[2].item,
            saveInto: local!items[2].item
          ),
          a!integerField(
            value: local!items[2].qty,
            saveInto: local!items[2].qty,
            align: "RIGHT"
          ),
          a!floatingPointField(
            value: local!items[2].unitPrice,
            saveInto: local!items[2].unitPrice,
            align: "RIGHT"
          ),
          a!textField(
            value: dollar(tointeger(local!items[2].qty) * todecimal(local!items[2].unitPrice)),
            readOnly: true,
            align: "RIGHT"
          )
        }
      )
    }
  )
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    You can leverage a!forEach() to avoid hardcoding the grid rows:

     

    =load(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20}
      },
      a!gridLayout(
        label: "Grid Layout",
        instructions: "This is a grid layout",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(label: "Qty", align: "RIGHT"),
          a!gridLayoutHeaderCell(label: "Unit Price", align: "RIGHT"),
          a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
        },
        rows: a!forEach(
          items: local!items,
          expression: a!gridRowLayout(
            contents: {
                a!textField(
                value: index(fv!item, "item", null),
                saveInto: fv!item.item
              ),
              a!integerField(
                value: index(fv!item, "qty", null),
                saveInto: fv!item.qty,
                align: "RIGHT"
              ),
              a!floatingPointField(
                value: index(fv!item, "unitPrice", null),
                saveInto: fv!item.unitPrice,
                align: "RIGHT"
              ),
              a!textField(
                value: dollar(tointeger(index(fv!item, "qty", 0)) * todecimal(index(fv!item, "unitPrice", 0))),
                readOnly: true,
                align: "RIGHT"
              )
            }
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    You can leverage a!forEach() to avoid hardcoding the grid rows:

     

    =load(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20}
      },
      a!gridLayout(
        label: "Grid Layout",
        instructions: "This is a grid layout",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(label: "Qty", align: "RIGHT"),
          a!gridLayoutHeaderCell(label: "Unit Price", align: "RIGHT"),
          a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
        },
        rows: a!forEach(
          items: local!items,
          expression: a!gridRowLayout(
            contents: {
                a!textField(
                value: index(fv!item, "item", null),
                saveInto: fv!item.item
              ),
              a!integerField(
                value: index(fv!item, "qty", null),
                saveInto: fv!item.qty,
                align: "RIGHT"
              ),
              a!floatingPointField(
                value: index(fv!item, "unitPrice", null),
                saveInto: fv!item.unitPrice,
                align: "RIGHT"
              ),
              a!textField(
                value: dollar(tointeger(index(fv!item, "qty", 0)) * todecimal(index(fv!item, "unitPrice", 0))),
                readOnly: true,
                align: "RIGHT"
              )
            }
          )
        )
      )
    )

Children