Fetch Total count Editable Grid

Certified Associate Developer

I have a editable grid,and I am using  totalcount:count(local!data) to show no. of rows in a gridlayout ,but for example I am removing any row from grid it is still showing same count value but I want it to be dynamic based on number of rows added and removed.

  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    Could it be that you have any null values in that data? My question would be, where do these null values come from? Try to not add any null values or use the length() function which ignores null values.

  • Can you share your expression? You might need to update a local variable, but it's hard to tell what's wrong without seeing your expression. Also just keep in mind that the "totalCount" parameter doesn't really do much - it's only purpose is to display the total count in the bottom of the grid (if there are 5 or more items) - it isn't required to build the grid.

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    Hi  can you please try this below code may it can help you

    a!localVariables(
      local!employees: {
        a!map(
          id: 1,
          firstName: "John",
          lastName: "Smith",
          department: "Engineering",
          title: "Director",
          phoneNumber: "555-123-4567",
          startDate: today() - 360
        ),
        a!map(
          id: 2,
          firstName: "Michael",
          lastName: "Johnson",
          department: "Finance",
          title: "Analyst",
          phoneNumber: "555-987-6543",
          startDate: today() - 360
        ),
        a!map(
          id: 3,
          firstName: "Mary",
          lastName: "Reed",
          department: "Engineering",
          title: "Software Engineer",
          phoneNumber: "555-456-0123",
          startDate: today() - 240
        ),
        
      },
      a!formLayout(
        label: "Employee Data",
        contents: {
          a!gridLayout(
            totalCount: count(local!employees),
            headerCells: {
              a!gridLayoutHeaderCell(label: "First Name"),
              a!gridLayoutHeaderCell(label: "Last Name"),
              a!gridLayoutHeaderCell(label: "Department"),
              a!gridLayoutHeaderCell(label: "Title"),
              a!gridLayoutHeaderCell(label: "Phone Number"),
              a!gridLayoutHeaderCell(label: "Start Date", align: "RIGHT"),
              a!gridLayoutHeaderCell(label: "")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            rows: a!forEach(
              items: local!employees,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "first name " & fv!index,
                    value: fv!item.firstName,
                    saveInto: fv!item.firstName,
                    required: true
                  ),
                  a!textField(
                    label: "last name " & fv!index,
                    value: fv!item.lastName,
                    saveInto: fv!item.lastName,
                    required: true
                  ),
                  a!dropdownField(
                    label: "department " & fv!index,
                    placeholder: "-- Select -- ",
                    choiceLabels: {
                      "Corporate",
                      "Engineering",
                      "Finance",
                      "Human Resources",
                      "Professional Services",
                      "Sales"
                    },
                    choiceValues: {
                      "Corporate",
                      "Engineering",
                      "Finance",
                      "Human Resources",
                      "Professional Services",
                      "Sales"
                    },
                    value: fv!item.department,
                    saveInto: fv!item.department,
                    required: true
                  ),
                  a!textField(
                    label: "title " & fv!index,
                    value: fv!item.title,
                    saveInto: fv!item.title,
                    required: true
                  ),
                  a!textField(
                    label: "phone number " & fv!index,
                    placeholder: "555-456-7890",
                    value: fv!item.phoneNumber,
                    saveInto: fv!item.phoneNumber
                  ),
                  a!dateField(
                    label: "start date " & fv!index,
                    value: fv!item.startDate,
                    saveInto: fv!item.startDate,
                    required: true,
                    align: "RIGHT"
                  ),
                  a!richTextDisplayField(
                    value: a!richTextIcon(
                      icon: "close",
                      altText: "delete " & fv!index,
                      caption: "Remove " & fv!item.firstName & " " & fv!item.lastName,
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            local!employees,
                            remove(local!employees, save!value)
                          )
                        }
                      ),
                      linkStyle: "STANDALONE",
                      color: "NEGATIVE"
                    )
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Employee",
              value: { startDate: today() + 1 },
              saveInto: {
                a!save(
                  local!employees,
                  append(local!employees, save!value)
                )
              }
            ),
            rowHeader: 1
          )
        }
      )
    )

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    Hi  can you please try this code

    a!localVariables(
      local!employees: {
        a!map(
          id: 1,
          firstName: "John",
          lastName: "Smith",
          department: "Engineering",
          title: "Director",
          phoneNumber: "555-123-4567",
          startDate: today() - 360
        ),
        a!map(
          id: 2,
          firstName: "Michael",
          lastName: "Johnson",
          department: "Finance",
          title: "Analyst",
          phoneNumber: "555-987-6543",
          startDate: today() - 360
        ),
        a!map(
          id: 3,
          firstName: "Mary",
          lastName: "Reed",
          department: "Engineering",
          title: "Software Engineer",
          phoneNumber: "555-456-0123",
          startDate: today() - 240
        ),
        
      },
      a!formLayout(
        label: "Employee Data",
        contents: {
          a!gridLayout(
            totalCount: count(local!employees),
            headerCells: {
              a!gridLayoutHeaderCell(label: "First Name"),
              a!gridLayoutHeaderCell(label: "Last Name"),
              a!gridLayoutHeaderCell(label: "Department"),
              a!gridLayoutHeaderCell(label: "Title"),
              a!gridLayoutHeaderCell(label: "Phone Number"),
              a!gridLayoutHeaderCell(label: "Start Date", align: "RIGHT"),
              a!gridLayoutHeaderCell(label: "")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            rows: a!forEach(
              items: local!employees,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "first name " & fv!index,
                    value: fv!item.firstName,
                    saveInto: fv!item.firstName,
                    required: true
                  ),
                  a!textField(
                    label: "last name " & fv!index,
                    value: fv!item.lastName,
                    saveInto: fv!item.lastName,
                    required: true
                  ),
                  a!dropdownField(
                    label: "department " & fv!index,
                    placeholder: "-- Select -- ",
                    choiceLabels: {
                      "Corporate",
                      "Engineering",
                      "Finance",
                      "Human Resources",
                      "Professional Services",
                      "Sales"
                    },
                    choiceValues: {
                      "Corporate",
                      "Engineering",
                      "Finance",
                      "Human Resources",
                      "Professional Services",
                      "Sales"
                    },
                    value: fv!item.department,
                    saveInto: fv!item.department,
                    required: true
                  ),
                  a!textField(
                    label: "title " & fv!index,
                    value: fv!item.title,
                    saveInto: fv!item.title,
                    required: true
                  ),
                  a!textField(
                    label: "phone number " & fv!index,
                    placeholder: "555-456-7890",
                    value: fv!item.phoneNumber,
                    saveInto: fv!item.phoneNumber
                  ),
                  a!dateField(
                    label: "start date " & fv!index,
                    value: fv!item.startDate,
                    saveInto: fv!item.startDate,
                    required: true,
                    align: "RIGHT"
                  ),
                  a!richTextDisplayField(
                    value: a!richTextIcon(
                      icon: "close",
                      altText: "delete " & fv!index,
                      caption: "Remove " & fv!item.firstName & " " & fv!item.lastName,
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            local!employees,
                            remove(local!employees, save!value)
                          )
                        }
                      ),
                      linkStyle: "STANDALONE",
                      color: "NEGATIVE"
                    )
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Employee",
              value: { startDate: today() + 1 },
              saveInto: {
                a!save(
                  local!employees,
                  append(local!employees, save!value)
                )
              }
            ),
            rowHeader: 1
          )
        }
      )
    )

  • +1
    Certified Associate Developer

    As long as the added/removed rows are altering local!data directly, your totalCount should be updated dynamically as well. It might have something to do with how you have configured addRowLink. As Peter mentioned, it's difficult to tell what needs fixing without looking at the expression.

  • +1
    Certified Senior Developer

     

    As others have mentioned, Please share your code snippet, so that we will understand what are you trying to do in the saveInto of the remove action.

    Also make sure your data that is being used in the grid and the remove actions saveInto reflect the same variable. Your count will be displayed only when the total number of rows in your data are more than or equal to Five.

  • +1
    Certified Associate Developer
    in reply to Peter Lewis

    Hi  ,yes I was making mistake while updating the local variable,when I was removing a row it was not getting removed from the local variable instead it was just updating isActive as false.I fixed the code.Thankyou

  • +1
    Certified Associate Developer
    in reply to Vedant Ambarkar

    HI  ,yes I was making mistake while updating the local variable,when I was removing a row after clicking cross link, it was not getting removed from the local variable instead it was just updating isActive as false.I fixed the code.Thankyou

  • +1
    Certified Associate Developer
    in reply to Konduru Chaitanya

    Hi  ,yes there was issue in the saveInto part of remove action,I was making mistake while updating the local variable,when I was removing a row after clicking cross link, it was not getting removed from the local variable instead it was just updating isActive as false.I fixed the code.Thankyou

  • 0
    Certified Associate Developer
    in reply to baji mekala

    Hi   ,I was making mistake while updating the local variable,when I was removing a row it was not getting removed from the local variable instead it was just updating isActive as false.I fixed the code.Thankyou