grouping in Grid

Certified Senior Developer

How can we group rows in Readonly grid

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    You can group the data before passing it in DB or in expression.
    Or
    You expecting something different?

  • 0
    Certified Senior Developer
    in reply to Shubham Aware

    assume that I have a field - Job Type  for that field I have values Software for 2 rows then I need group that two rows into single row

  • 0
    Certified Lead Developer
    in reply to meharunnisas068858

    You have to aggregate data.
    Hope you are expecting similar..

    a!localVariables(
      local!employees: {
        a!map(name: "John", jobType: "Software", salary: 50000),
        a!map(name: "Sarah", jobType: "Software", salary: 60000),
        a!map(name: "Mike", jobType: "Testing", salary: 45000),
        a!map(name: "Lisa", jobType: "Testing", salary: 55000),
        a!map(name: "Tom", jobType: "Management", salary: 70000),
        a!map(name: "Emma", jobType: "Management", salary: 65000)
      },
    
      /* Get unique job types */
      local!uniqueJobTypes: union(local!employees.jobType, local!employees.jobType),
    
      /* Aggregate data by Job Type */
      local!aggregatedData: a!forEach(
        items: local!uniqueJobTypes,
        expression: a!localVariables(
          local!currentJobType: fv!item,
          local!filteredEmployees: a!forEach(
            items: local!employees,
            expression: if(fv!item.jobType = local!currentJobType, fv!item, null)
          ),
          local!validEmployees: reject(fn!isnull, local!filteredEmployees),
          a!map(
            jobType: local!currentJobType,
            employeeNames: joinarray(local!validEmployees.name, ", "),
            totalSalary: sum(local!validEmployees.salary),
            employeeCount: count(local!validEmployees)
          )
        )
      ),
    
      a!gridField(
        label: "Employees Grouped by Job Type",
        data: local!aggregatedData,
        columns: {
          a!gridColumn(
            label: "Job Type",
            value: fv!row.jobType
          ),
          a!gridColumn(
            label: "Employees",
            value: fv!row.employeeNames
          ),
          a!gridColumn(
            label: "Count",
            value: fv!row.employeeCount
          ),
          a!gridColumn(
            label: "Total Salary",
            value: fv!row.totalSalary
          )
        }
      )
    )

  • 0
    Certified Lead Developer

    Make use of aggregation in the queryRecordType(). You can use a!aggregationFields() when defining the fields for querying the record.