Column Sum in a Grid

Hi,

Can someone please provide a small & clear example of code snippet on how to find total for column values in a grid ?
I am new to Appian and finding difficult in understanding the related blogs & docs.

Usecase: I have two columns. Rows appear upon clicking Add Dynamic link. last row of the grid should have Total/Sum of respective columns row data

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Do you have any example code for what you've tried so far?

  • Thank you Mike for the response. Here is my code 

    a!localVariables(
      local!questionID: {"230108"},
      local!gridQuestionsList:rule!GPO_quesDetailsInput(questionInputID: local!questionID),
      local!program:"test",
    
      
      a!gridLayout(
        headerCells: {
             a!forEach(
              items: local!gridQuestionsList.questionID,
              expression: 
                a!localVariables(
                  local!list: rule!GPO_questionDetails(questionID: fv!item),
                  a!gridLayoutHeaderCell(label: local!list.label)
                )),
            if(not(rule!APN_isTrue(ri!isReadOnly)),a!gridLayoutHeaderCell(label: ""),{})
         },
        rows: a!forEach(
          items: local!questionID,
          expression: a!gridRowLayout(
            contents: {
              if(
                rule!APN_arrayLength(local!questionID) >= fv!index,
              a!dropdownField(
                labelPosition: "COLLAPSED",
                placeholder: "Please select one",
                choiceLabels: {"Consumer Credit","Consumer Debit","Prepaid","Ecommerece"},
                choiceValues: {"Consumer Credit","Consumer Debit","Prepaid","Ecommerece"},
                value:"",
                saveInto: local!program,
                required: not(rule!APN_isTrue(ri!isReadOnly)),
                disabled: rule!APN_isTrue(ri!isReadOnly)
              ),
              a!richTextDisplayField(
                label:"Total",
                labelPosition: "COLLAPSED",
                value:{
                  a!richTextItem(
                    text: "Total:",
                    style: "STRONG"
                  )
                }
              )
              ),
              a!textField(
                labelPosition: "COLLAPSED",
                placeholder: "MM/YYYY",
                value: "",
                saveInto: local!program,
                required: not(rule!APN_isTrue(ri!isReadOnly)),
                readOnly: rule!APN_isTrue(ri!isReadOnly),
     
              ),
              a!floatingPointField(
                value: "",
                saveInto: local!program
              ),
             a!imageField(
                label: "delete " & fv!index,
                images: a!documentImage(
                  document: a!iconIndicator("REMOVE"),
                  altText: "Remove Row",
                  link: a!dynamicLink(
                    value: fv!index,
                    saveInto: {
                      a!save(local!program, remove(local!program, save!value))
                    }
                  )
                ),
                size: "ICON"
              )
            }
          )  
        ),
        addRowlink: if(
          not(rule!APN_isTrue(ri!isReadOnly)),
          a!dynamicLink(
            label: "Add",
            value: (
              startDate: today() + 1
            ),
            saveInto: {
              a!save(local!program, append(local!program, save!value))
            }
          ),
          {}
        ),
        rowHeader: 1
      )
    )
    


    I have tried this. But not able see Total label at all.
    Also not sure how can I sum up values.

Reply
  • Thank you Mike for the response. Here is my code 

    a!localVariables(
      local!questionID: {"230108"},
      local!gridQuestionsList:rule!GPO_quesDetailsInput(questionInputID: local!questionID),
      local!program:"test",
    
      
      a!gridLayout(
        headerCells: {
             a!forEach(
              items: local!gridQuestionsList.questionID,
              expression: 
                a!localVariables(
                  local!list: rule!GPO_questionDetails(questionID: fv!item),
                  a!gridLayoutHeaderCell(label: local!list.label)
                )),
            if(not(rule!APN_isTrue(ri!isReadOnly)),a!gridLayoutHeaderCell(label: ""),{})
         },
        rows: a!forEach(
          items: local!questionID,
          expression: a!gridRowLayout(
            contents: {
              if(
                rule!APN_arrayLength(local!questionID) >= fv!index,
              a!dropdownField(
                labelPosition: "COLLAPSED",
                placeholder: "Please select one",
                choiceLabels: {"Consumer Credit","Consumer Debit","Prepaid","Ecommerece"},
                choiceValues: {"Consumer Credit","Consumer Debit","Prepaid","Ecommerece"},
                value:"",
                saveInto: local!program,
                required: not(rule!APN_isTrue(ri!isReadOnly)),
                disabled: rule!APN_isTrue(ri!isReadOnly)
              ),
              a!richTextDisplayField(
                label:"Total",
                labelPosition: "COLLAPSED",
                value:{
                  a!richTextItem(
                    text: "Total:",
                    style: "STRONG"
                  )
                }
              )
              ),
              a!textField(
                labelPosition: "COLLAPSED",
                placeholder: "MM/YYYY",
                value: "",
                saveInto: local!program,
                required: not(rule!APN_isTrue(ri!isReadOnly)),
                readOnly: rule!APN_isTrue(ri!isReadOnly),
     
              ),
              a!floatingPointField(
                value: "",
                saveInto: local!program
              ),
             a!imageField(
                label: "delete " & fv!index,
                images: a!documentImage(
                  document: a!iconIndicator("REMOVE"),
                  altText: "Remove Row",
                  link: a!dynamicLink(
                    value: fv!index,
                    saveInto: {
                      a!save(local!program, remove(local!program, save!value))
                    }
                  )
                ),
                size: "ICON"
              )
            }
          )  
        ),
        addRowlink: if(
          not(rule!APN_isTrue(ri!isReadOnly)),
          a!dynamicLink(
            label: "Add",
            value: (
              startDate: today() + 1
            ),
            saveInto: {
              a!save(local!program, append(local!program, save!value))
            }
          ),
          {}
        ),
        rowHeader: 1
      )
    )
    


    I have tried this. But not able see Total label at all.
    Also not sure how can I sum up values.

Children