Need help on read only grid

Certified Associate Developer

load(
  local!empStatus: {
    { name: "Ajay", status: "test1" },
    { name: "Ajay", status: "test2" },
    { name: "kumar", status: "test3" },
    { name: "phani", status: "test4" }
  },
  local!empDetail: {
    { name: "Ajay" },
    { name: "kumar" },
    { name: "phani" }
  },
  a!boxLayout(
    label: "Form",
    contents: {
      a!gridField(
        label: "grid",
        data: local!empDetail,
        pageSize: 5,
        pagingSaveInto: fv!pagingInfo,
        columns: {
          a!gridColumn(label: "Name", value: fv!row.name),
          a!gridColumn(
            label: "Status",
            value: a!forEach(
              items: local!empStatus,
              expression: fv!item.status
            )
          )
        }
      )
    }
  )
)

Hi All,

I have added the sample code and the output where I need to display the corresponding status for that particular name.

for example: Name: Ajay   Status should be Test1, Test2 and similarly

for                Name: Kumar Status should be Test3

and for         Name: Phani status should be Test4.

Thanks in advance,

Gousii.

  Discussion posts and replies are publicly visible

  • Sanchit and Tejpals already gave you workable solutions above (and props to Harshit for pointing out that, really at this point everyone should be using a!localVariables for this...)

    But I wanted to chime in with a recommendation towards a usual approach of mine, which is to abstract complicated processing behind additional local variables when necessary.  In this case the idea is to construct a whole new array-of-maps that will contain the "Name" property as well as a pre-evaluated copy of the Statuses looked up from the predefined Status List, formatted cleanly and separated by a comma (just for example).  Then we just use that new local variable as the source for the grid; any changes made to the original data will cause this to auto-update too, so we should be good there.

    One of the main draws to this approach is we don't have to do potentially complex processing in the grid column itself (which isn't always bad to do, but often will make it easier to understand the code in the future, among other things):

    The entire code body isn't much changed, other than the addition of the declaration for local!gridData:

    a!localVariables(
      local!empStatus: {
        { name: "Ajay", status: "test1" },
        { name: "Ajay", status: "test2" },
        { name: "kumar", status: "test3" },
        { name: "phani", status: "test4" }
      },
      local!empDetail: {
        { name: "Ajay" },
        { name: "kumar" },
        { name: "phani" }
      },
      
      local!gridData: a!forEach(
        local!empDetail,
        a!map(
          name: fv!item.name,
          statusList: joinarray(
            index(
              local!empStatus.status,
              wherecontains(fv!item.name, local!empStatus.name),
              {}
            ),
            ", "
          )
        )
      ),
      
      a!boxLayout(
        label: "Form",
        contents: {
          a!gridField(
            label: "grid",
            data: local!gridData,
            pageSize: 5,
            columns: {
              a!gridColumn(
                label: "Name",
                sortField: "name",
                value: fv!row.name
              ),
              a!gridColumn(
                label: "Status",
                value: fv!row.statusList
              )
            }
          )
        }
      )
    )