Skip to content

fix(grid): include nested sub-groups when exporting pivot breakdown to CSV in GridGroupingsEngine #908

Description

@ZhuchkaTriplesix

Summary

In GridGroupingsEngine.exportPivotToCsv (lib/features/workspace/grid_groupings_engine.dart, lines 221–238), the engine iterates exclusively over the root-level groups list:

for (final g in groups) {
  final aggStr = g.aggValue != null ? g.aggValue!.toStringAsFixed(2) : '-';
  buffer.writeln(
    '"${g.groupKey.replaceAll('"', '""')}",${g.count},${g.percentage.toStringAsFixed(2)}%,$aggStr',
  );
}

The engine supports multi-level hierarchical grouping via groupColIndices and populates nested subGroups on each GroupedCategory.

However, exportPivotToCsv completely ignores all nested subGroups. When the user groups by multiple columns (e.g. Department -> Role -> Status), all nested sub-groups are completely omitted from the exported CSV file, producing only the root summary and losing the detailed multi-level breakdown.

Repro

  1. In the Groupings / Pivot View panel, add 2 or more columns to group by (e.g. Country and City).
  2. Expand the tree to see the nested categories in the UI.
  3. Click 'Export to CSV'.
  4. Inspect the generated CSV file; observe that only the root Country rows are exported; all City sub-groups are missing.

Scope

  • Recursively traverse g.subGroups in exportPivotToCsv with indentation or compound keys (or multi-column headers reflecting grouping levels).
  • Ensure row counts, percentages, and aggregated values for nested sub-groups are preserved in the export.
  • Add unit tests for multi-level pivot CSV export.

Out of scope

  • Excel / XLSX binary format export.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingdata-gridInteractive data grid, cell editor, filtering, groupings

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions