Re-ordering dynamic list

Certified Lead Developer

We have a dynamic array containing lists of data. Dynamic here meaning data1, data2..etc could be any length.

We need a screen that allows users to reorder this data and we are attempting to do this with a gridLayout with allowRowReordering = true.

When attempting this example below, we are seeing the error Expression evaluation error at function a!gridLayout [line 15]: A grid layout component [label="data1"] has an invalid value for "rowOrderData". The value must be a list of records, a list of maps, or a list of dictionaries.

a!localVariables(
  local!map: { "data1", "data2" },
  local!data: {
    data1: {
      { sortOrder: 1, label: "A" },
      { sortOrder: 2, label: "B" }
    },
    data2: {
      { sortOrder: 1, label: "C" },
      { sortOrder: 2, label: "D" }
    }
  },
  a!forEach(
    items: local!map,
    expression: a!gridLayout(
      label: fv!item,
      headerCells: {
        a!gridLayoutHeaderCell(label: "Checklist Sections")
      },
      rows: a!forEach(
        items: local!data[fv!item],
        expression: a!gridRowLayout(
          contents: a!textField(value: fv!item.label, readOnly: true)
        )
      ),
      allowRowReordering: true,
      rowOrderData: local!data[fv!item],
      rowOrderField: "sortOrder"
    )
  )
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    The code you shared was converting list of Dictionaries in a List of Variants. For row order the attributes need a structured map or dictionary. Try the below code where some data maps are created so that a linear structured list of dictionaries are formed as grid data source. 

    a!localVariables(
      local!map: { "data1", "data2" },
      local!data: {
        data1: {
          { sortOrder: 1, label: "A" },
          { sortOrder: 2, label: "B" }
        },
        data2: {
          { sortOrder: 1, label: "C" },
          { sortOrder: 2, label: "D" }
        }
      },
      a!forEach(
        items: local!map,
        expression: a!localVariables(
          local!dictionary: a!foreach(
            local!data[fv!item],
            a!map(
              label: fv!item.label,
              sortOrder: fv!item.sortOrder
            )
          ),
          a!gridLayout(
            label: local!dictionary,
            headerCells: {
              a!gridLayoutHeaderCell(label: "Checklist Sections")
            },
            rows: a!forEach(
              items: local!dictionary,
              expression: a!gridRowLayout(
                contents: a!textField(value: fv!item.label, readOnly: true)
              )
            ),
            allowRowReordering: true,
            rowOrderData: local!dictionary,
            rowOrderField: "sortOrder"
          )
        )
      )
    )

    Hope it helps!

Reply
  • 0
    Certified Lead Developer

    The code you shared was converting list of Dictionaries in a List of Variants. For row order the attributes need a structured map or dictionary. Try the below code where some data maps are created so that a linear structured list of dictionaries are formed as grid data source. 

    a!localVariables(
      local!map: { "data1", "data2" },
      local!data: {
        data1: {
          { sortOrder: 1, label: "A" },
          { sortOrder: 2, label: "B" }
        },
        data2: {
          { sortOrder: 1, label: "C" },
          { sortOrder: 2, label: "D" }
        }
      },
      a!forEach(
        items: local!map,
        expression: a!localVariables(
          local!dictionary: a!foreach(
            local!data[fv!item],
            a!map(
              label: fv!item.label,
              sortOrder: fv!item.sortOrder
            )
          ),
          a!gridLayout(
            label: local!dictionary,
            headerCells: {
              a!gridLayoutHeaderCell(label: "Checklist Sections")
            },
            rows: a!forEach(
              items: local!dictionary,
              expression: a!gridRowLayout(
                contents: a!textField(value: fv!item.label, readOnly: true)
              )
            ),
            allowRowReordering: true,
            rowOrderData: local!dictionary,
            rowOrderField: "sortOrder"
          )
        )
      )
    )

    Hope it helps!

Children
No Data