How to create two text fields in single column in grid and make default selection of all rows in grid

Certified Senior Developer

Hi Champs,

I have an requirement that in editable grid i want two fields in a single column and also  make all rows selectable by default .please, let me help for this issue.  As in figure i want the result.

Thanks in advance..

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Hi,

    Please see the below code as an example for your requirements. I hope it will help... let me know if any concerns.

    a!localVariables(
      local!condition: cons!ZMS_PEN_CONDITIONS,
      local!types: cons!ZMS_PEN_TYPES,
      a!formLayout(
        label: "Add Multiple Pens Data",
        contents: {
          a!gridLayout(
            totalCount: count(ri!items),
            headerCells: {
              a!gridLayoutHeaderCell(label: "Pen Name"),
              a!gridLayoutHeaderCell(label: "Type"),
              a!gridLayoutHeaderCell(label: "Condition"),
              a!gridLayoutHeaderCell(label: "Image"),
              a!gridLayoutHeaderCell(label: "Description"),
              /* For the "Remove" column */
              a!gridLayoutHeaderCell(label: "")
            },
            /* Only needed when some columns need to be narrow */
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 1),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 1),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            rows: a!forEach(
              items: ri!items,
              expression: a!gridRowLayout(
                id: fv!index,
                contents: {
                  a!textField(
                    label: "pen name " & fv!index,
                    value: fv!item.penname,
                    saveInto: fv!item.penname,
                    required: true
                  ),
                  a!dropdownField(
                    label: "condition " & fv!index,
                    placeholder: "-- Select -- ",
                    choiceLabels: local!types,
                    choiceValues: local!types,
                    value: fv!item.pentype,
                    saveInto: fv!item.pentype,
                    required: true
                  ),
                  a!dropdownField(
                    label: "condition " & fv!index,
                    placeholder: "-- Select -- ",
                    choiceLabels: local!condition,
                    choiceValues: local!condition,
                    value: fv!item.pencondition,
                    saveInto: fv!item.pencondition,
                    required: true
                  ),
                  a!fileUploadField(
                    target: cons!ZMS_PEN_IMAGE_FOLDER,
                    maxSelections: 1,
                    value: fv!item.penimage,
                    saveInto: fv!item.penimage,
                    required: true,
                    requiredMessage: "pen image is required",
                    validations: {
                      a!localVariables(
                        local!invalidExtensions: difference(
                          upper(fv!files.extension),
                          { "PNG", "JPG" }
                        ),
                        if(
                          length(local!invalidExtensions) > 0,
                          "Attachments must be images. Remove: " & index(
                            fv!files,
                            "name",
                            wherecontains(
                              local!invalidExtensions,
                              upper(fv!files.extension)
                            ),
                            {}
                          ),
                          ""
                        )
                      ),
                      if(
                        or(fv!files.size > 300000),
                        "Attachments may not exceed 300KB. Remove: " & index(
                          fv!files,
                          "name",
                          where(fv!files.size > 300000),
                          {}
                        ),
                        ""
                      )
                    },
                    buttonStyle: "SECONDARY",
                    buttonSize: "STANDARD"
                  ),
                  a!textField(
                    value: fv!item.characteristics,
                    saveInto: fv!item.characteristics,
                    characterLimit: 100,
                    required: true,
                    validationGroup: "main"
                  ),
                  /* For the Removal Column*/
                  a!richTextDisplayField(
                    value: a!richTextIcon(
                      icon: "close",
                      altText: "delete " & fv!index,
                      caption: "Remove " & fv!item.penname,
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(ri!items, remove(ri!items, save!value))
                        }
                      ),
                      linkStyle: "STANDALONE",
                      color: "NEGATIVE"
                    )
                  )
                }
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Pen",
              value: 'type!{urn:com:appian:types:ZMS}ZMS_Pens'(
                createdby: loggedInUser(),
                createddate: now(),
                status: "Active"
              ),
              saveInto: {
                a!save(ri!items, append(ri!items, save!value))
              }
            ),
            rowHeader: 1
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            saveInto: a!writeToDataStoreEntity(
              dataStoreEntity: cons!ZMS_DSE_PENS,
              valueToStore: ri!items/*onSuccess: ri!items*/
              
            ),
            submit: true
          )
        )
      )
    )

    Please modify the code as per your fields.

  • 0
    Certified Senior Developer
    in reply to Shubham Kumar

    Hi  Shubham Kumar,

    I  want one dropdown field and paragraph field in single column in grid... As in image i kept earlier in a column reason

  • Adding two components in a single cell is not possible. One cell can only have one component. 
    I am assuming that you want all the rows to be selected NOT SELECTABLE by default. So for this, you need to pass the list of indexes of the rows the variable that is storing the selectionValue. 

  • 0
    Certified Senior Developer
    in reply to saijoshnavi2992

    For two fields in a column in grid is not possible. i hope you are using it for related value so for that you can create 2 columns and those 2 are related to each other. For by defauly all the selected row, you have to create a local variable to store to selection value and by default use enumerate(count(local!griddata))+1.

  • 0
    Certified Senior Developer
    in reply to Deepak gupta

    Thank You deepak for your response

  • 0
    Certified Lead Developer
    in reply to saijoshnavi2992

    The grid selection is based on the IDs of the individual records. Not on the index of the row in the grid.

  • It is an editable grid. How can we have IDs if they are constructing the data in this grid?

  • The documentation for the gridRowLayout states:

    a!gridRowLayout( contents, id, selectionDisabled, showWhen )

    and the id-value is what is stored in the selection. In the above code example fv!index is assigned.

    I just wanted to make clear that the following:

    "For by defauly all the selected row, you have to create a local variable to store to selection value and by default use enumerate(count(local!griddata))+1."

    is only true when the id field is set to fv!index. And this is NOT the default.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    Hey Stefan, correct, in the gridRowLayout we have to set id to fv!index.