add grid again when i click addrow an remove the grid

Hi i have written code like this to get a grid it's a editable grid and for this now when i click add row then complete grid has to be added 

how can i write logic for it can anyone help on this 

a!gridLayout(
      labelPosition: "COLLAPSED",
      headerCells: {
        a!gridLayoutHeaderCell(
          align: "LEFT"
        ),
        a!gridLayoutHeaderCell(
          align: "LEFT"
        )
      },
      columnConfigs: {
        a!gridLayoutColumnConfig(
          width: "DISTRIBUTE",
          weight: 5
        ),
        a!gridLayoutColumnConfig(
          width: "DISTRIBUTE",
          weight: 3
        )
      },
      rows: a!forEach(
        items: ri!crAPPContractExtension_cdt,
        expression: with(
          local!SingleREFContractExtension_cdt: index(
            ri!crREFContractExtension_cdt,
            wherecontains(
              fv!item.extensionRefId_int,
              ri!crREFContractExtension_cdt.id_int
            ),
            {}
          ),
          a!gridRowLayout(
            contents: {
              a!textField(
                value: fv!item.fieldName_txt,
                readOnly: true()
              ),
              choose(
                if(
                  index(
                    local!SingleREFContractExtension_cdt,
                    "fieldType_txt",
                    {}
                  ) = cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[12],
                  1,
                  if(
                    index(
                      local!SingleREFContractExtension_cdt,
                      "fieldType_txt",
                      {}
                    ) = cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[1],
                    2,
                    if(
                      index(
                        local!SingleREFContractExtension_cdt,
                        "fieldType_txt",
                        {}
                      ) = cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[3],
                      3,
                      if(
                        index(
                          local!SingleREFContractExtension_cdt,
                          "fieldType_txt",
                          {}
                        ) = cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[5],
                        4,
                        if(
                          index(
                            local!SingleREFContractExtension_cdt,
                            "fieldType_txt",
                            {}
                          ) = cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[4],
                          5,
                          if(
                            contains(
                              split(
                                index(
                                  local!SingleREFContractExtension_cdt,
                                  "fieldType_txt",
                                  {}
                                ),
                                ": "
                              ),
                              cons!CR_APP_USERINPUTFIELD_IDENTIFIERS[7]
                            ),
                            6,
                            7
                          )
                        )
                      )
                    )
                  )
                ),
                choice1: a!radioButtonField(
                  choiceLabels: cons!CR_APP_TXT_CHOICE_LABELS_YES_NO,
                  choiceValues: touniformstring(
                    cons!CR_APP_INT_CHOICE_VALUES
                  ),
                  choiceLayout: "COMPACT",
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt,
                  disabled: ri!IsReadOnly_bool
                ),
                choice2: a!textField(
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt,
                  readOnly: if(
                    index(
                      local!SingleREFContractExtension_cdt,
                      "readOnlyFlag_int",
                      {}
                    ) = 1,
                    true(),
                    false()
                  )
                ),
                choice3: a!dateField(
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt,
                  readOnly: if(
                    index(
                      local!SingleREFContractExtension_cdt,
                      "readOnlyFlag_int",
                      {}
                    ) = 1,
                    true(),
                    false()
                  )
                ),
                choice4: a!integerField(
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt,
                  readOnly: if(
                    index(
                      local!SingleREFContractExtension_cdt,
                      "readOnlyFlag_int",
                      {}
                    ) = 1,
                    true(),
                    false()
                  ),
                  validations: rule!CR_Fn_setMaximumLengthForInteger(
                    inputText_txt: fv!item.value_txt,
                    maxLength_int: 7
                  )
                ),
                choice5: a!integerField(
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt,
                  validations: rule!CR_Fn_setMaximumLengthForInteger(
                    inputText_txt: fv!item.value_txt,
                    maxLength_int: 7
                  ),
                  readOnly: if(
                    index(
                      local!SingleREFContractExtension_cdt,
                      "readOnlyFlag_int",
                      {}
                    ) = 1,
                    true(),
                    false()
                  )
                ),
                choice6: a!dropdownField(
                  labelPosition: "COLLAPSED",
                  placeholderLabel: cons!CR_APP_TXT_PLACEHOLDER_VALUE,
                  choiceLabels: remove(
                    split(
                      split(
                        index(
                          local!SingleREFContractExtension_cdt,
                          "fieldType_txt",
                          {}
                        ),
                        ":"
                      ),
                      ";"
                    ),
                    1
                  ),
                  choiceValues: remove(
                    split(
                      split(
                        index(
                          local!SingleREFContractExtension_cdt,
                          "fieldType_txt",
                          {}
                        ),
                        ":"
                      ),
                      ";"
                    ),
                    1
                  ),
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt
                ),
                choice7: a!textField(
                  value: fv!item.value_txt,
                  saveInto: fv!item.value_txt
                )
              )
            }
          )
        )
      ),
      shadeAlternateRows: true,
      addRowLink: a!dynamicLink(
        value: true(),
        label: "Add Contract",
        saveInto: {
          a!save(
            ri!crAPPContractExtension_cdt,
           append(
             ri!crAPPContractExtension_cdt,
             'type!{urn:com:appian:types:NBF}CR_APP_ContractExtension'()
           )
          )
        }
      )
    )
this is the code for that grid.. even want to remove then complete grid has to be removed 

  Discussion posts and replies are publicly visible

Parents
  • That is a simple requirement, achievable with a simple loop. You can call your grid in the loop and the items of that loop should be an array that is increased or decreased based on of you add or remove. 

    Also, you have to create custom dynamic links to add or remove the grid. But just out of curiosity, what is your usecase? Why do you want multiple grids? 

  • yeah, am not sure how can i achieve that. am stuck with this task :( unable to progress on this.

    my use case when user wants to add more contract then hole grid has to be populated so they'll add if they willing it remove then it should be able to delete it 

  • +1
    Certified Lead Developer
    in reply to KM

    Check this

    = a!localVariables(
      local!items: {
        a!map(item: null, qty: null, unitPrice: null),
        
      },
      {
        a!forEach(
          items: local!items,
          expression: {
            a!sideBySideLayout(
              items: {
                a!sideBySideItem(
                  item: a!richTextDisplayField(label: "Products", ),
                  
                ),
                a!sideBySideItem(
                  item: a!richTextDisplayField(
                    align: "RIGHT",
                    value: a!richTextIcon(
                      icon: "times",
                      color: "NEGATIVE",
                      link: a!dynamicLink(
                        saveInto: a!save(
                          local!items,
                          remove(local!items, fv!index)
                        )
                      )
                    )
                  ),
                  
                ),
                
              }
            ),
            a!gridLayout(
              instructions: "Update the item name, quantity, or unit price.",
              headerCells: {
                a!gridLayoutHeaderCell(label: "Item"),
                a!gridLayoutHeaderCell(label: "Qty"),
                a!gridLayoutHeaderCell(label: "Unit Price"),
                a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
              },
              rows: {
                a!gridRowLayout(
                  contents: {
                    a!textField(
                      value: fv!item.item,
                      saveInto: fv!item.item
                    ),
                    a!integerField(value: fv!item.qty, saveInto: fv!item.qty),
                    a!floatingPointField(
                      value: fv!item.unitPrice,
                      saveInto: fv!item.unitPrice
                    ),
                    a!textField(
                      value: fv!item.qty,
                      readOnly: true,
                      align: "RIGHT"
                    )
                  }
                ),
                
              },
              rowHeader: 1
            ),
            
          }
        ),
        a!richTextDisplayField(
          value: a!richTextItem(
            text: "ADD GRID",
            link: a!dynamicLink(
              label: "Add new Grid",
              saveInto: a!save(
                local!items,
                append(
                  local!items,
                  a!map(item: null, qty: null, unitPrice: null)
                )
              )
            )
          )
        )
      }
    )
    
    

Reply
  • +1
    Certified Lead Developer
    in reply to KM

    Check this

    = a!localVariables(
      local!items: {
        a!map(item: null, qty: null, unitPrice: null),
        
      },
      {
        a!forEach(
          items: local!items,
          expression: {
            a!sideBySideLayout(
              items: {
                a!sideBySideItem(
                  item: a!richTextDisplayField(label: "Products", ),
                  
                ),
                a!sideBySideItem(
                  item: a!richTextDisplayField(
                    align: "RIGHT",
                    value: a!richTextIcon(
                      icon: "times",
                      color: "NEGATIVE",
                      link: a!dynamicLink(
                        saveInto: a!save(
                          local!items,
                          remove(local!items, fv!index)
                        )
                      )
                    )
                  ),
                  
                ),
                
              }
            ),
            a!gridLayout(
              instructions: "Update the item name, quantity, or unit price.",
              headerCells: {
                a!gridLayoutHeaderCell(label: "Item"),
                a!gridLayoutHeaderCell(label: "Qty"),
                a!gridLayoutHeaderCell(label: "Unit Price"),
                a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
              },
              rows: {
                a!gridRowLayout(
                  contents: {
                    a!textField(
                      value: fv!item.item,
                      saveInto: fv!item.item
                    ),
                    a!integerField(value: fv!item.qty, saveInto: fv!item.qty),
                    a!floatingPointField(
                      value: fv!item.unitPrice,
                      saveInto: fv!item.unitPrice
                    ),
                    a!textField(
                      value: fv!item.qty,
                      readOnly: true,
                      align: "RIGHT"
                    )
                  }
                ),
                
              },
              rowHeader: 1
            ),
            
          }
        ),
        a!richTextDisplayField(
          value: a!richTextItem(
            text: "ADD GRID",
            link: a!dynamicLink(
              label: "Add new Grid",
              saveInto: a!save(
                local!items,
                append(
                  local!items,
                  a!map(item: null, qty: null, unitPrice: null)
                )
              )
            )
          )
        )
      }
    )
    
    

Children
No Data