toggleExpandedRowGroup method

  1. @override
void toggleExpandedRowGroup({
  1. required PlutoRow rowGroup,
  2. bool notify = true,
})
inherited

Collapse or expand the group row.

Implementation

@override
void toggleExpandedRowGroup({
  required PlutoRow rowGroup,
  bool notify = true,
}) {
  assert(enabledRowGroups);

  if (!rowGroup.type.isGroup ||
      rowGroup.type.group.children.originalList.isEmpty) {
    return;
  }

  if (rowGroup.type.group.expanded) {
    final Set<Key> removeKeys = {};

    for (final child in _iterateRowAndGroup(rowGroup.type.group.children)) {
      removeKeys.add(child.key);
    }

    refRows.removeWhereFromOriginal((e) => removeKeys.contains(e.key));
  } else {
    final Iterable<PlutoRow> children = PlutoRowGroupHelper.iterateWithFilter(
      rowGroup.type.group.children,
      filter: (r) => true,
      childrenFilter: (r) => r.type.isGroup && r.type.group.expanded
          ? r.type.group.children.iterator
          : null,
    );

    final idx = refRows.indexOf(rowGroup);

    refRows.insertAll(idx + 1, children);
  }

  rowGroup.type.group.setExpanded(!rowGroup.type.group.expanded);

  if (isPaginated) {
    resetPage(resetCurrentState: false, notify: false);
  }

  if (rowGroupDelegate?.onToggled != null) {
    rowGroupDelegate!.onToggled!(
      row: rowGroup,
      expanded: rowGroup.type.group.expanded,
    );
  }

  updateCurrentCellPosition(notify: false);

  clearCurrentSelecting(notify: false);

  notifyListeners(notify, toggleExpandedRowGroup.hashCode);
}