How to implement custom fields to display in the gridField?

I want to implement a user-defined feature that allows specific fields to be displayed and the order to be adjusted.

For example, I currently have 5 columns(column 1-5) in readonly grid, and the user can present 3 of them as needed and can adjust the order, e.g. display [column 1, column 5, column 3].

Is there any way to implement this feature? Can you give me some advice?

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Senior Developer
    in reply to yans8297

    HI  ,

    Use the below code it will help 

    a!localVariables(
      local!data:{
        a!map(requestID:1,refNum:"LP012",subject:"Test1",asset:"Laptop"),
        a!map(requestID:2,refNum:"TB-2344",subject:"Test2",asset:"Tablet"),
      },
      local!gridFields1:{"Request Id","Reference Number","Subject","Asset"},
      local!selectedData,
      {
        a!multipleDropdownField(
          choiceLabels: local!gridFields1,
          choiceValues: local!gridFields1,
          label: "Column Types",
          placeholder: "--Select Columns--",
          value: local!selectedData,
          saveInto: local!selectedData
          
        ),
        a!gridField(
          label: "Read-only Grid",
          labelPosition: "ABOVE",
          data: local!data,
          columns: {
            a!gridColumn(
              label: "Request Id",
              value: fv!row.requestID,
              showWhen: if(
                a!isNotNullOrEmpty(local!selectedData),
                if(
                  contains(
                    touniformstring(local!selectedData),
                    touniformstring(local!gridFields1[1])
                  ),
                  true(),
                  false()
                ),
                true()
              )
    
    ,
              align: "END"
            ),
            a!gridColumn(
              label: "Reference Number",
              value: fv!row.refNum,
              showWhen: if(
                a!isNotNullOrEmpty(local!selectedData),
                if(
                  contains(
                    touniformstring(local!selectedData),
                    touniformstring(local!gridFields1[2])
                  ),
                  true(),
                  false()
                ),
                true()
              )
            ),
            a!gridColumn(
              label: "Subject",
              value:fv!row.subject,
              showWhen: if(
                a!isNotNullOrEmpty(local!selectedData),
                if(
                  contains(
                    touniformstring(local!selectedData),
                    touniformstring(local!gridFields1[3])
                  ),
                  true(),
                  false()
                ),
                true()
              )
            ),
            a!gridColumn(
              label: "Asset",
              value: fv!row.asset,
              align: "START",
              showWhen: if(
                a!isNotNullOrEmpty(local!selectedData),
                if(
                  contains(
                    touniformstring(local!selectedData),
                    touniformstring(local!gridFields1[4])
                  ),
                  true(),
                  false()
                ),
                true()
              )
            )
          },
          validations: {}
        )
        
      }
    )

Children
No Data