Skip to main content
July 26, 2022
Question

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

  • July 26, 2022
  • 10 replies
  • 4 views

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..

    10 replies

    shubhamk0004
    July 26, 2022

    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.

    July 26, 2022

    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

    July 26, 2022

    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.

    harshitb6843
    July 26, 2022

    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. 

    July 26, 2022

    Thank You