Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AFK surf Open agent GroupTrait ChangeGroup

From Leeroopedia
Knowledge Sources
Domains Database, Data_View, BlockSuite
Last Updated 2026-10-25 00:00 GMT

Overview

Concrete API that sets the group-by column on a view via the GroupTrait, retrieved from the current view's trait map using the shared groupTraitKey.

Description

GroupTrait.changeGroup configures which column a view groups its rows by. The trait is fetched from the current SingleView via traitGet(groupTraitKey). Calling changeGroup(columnId) resolves the target column, looks up its property meta, computes a defaultGroupBy (which carries the column id, type, and a default grouping strategy), and writes it via ops.groupBySet. Passing undefined clears the group-by. Grouping is view-scoped, so each view (table, kanban) can group by a different column. The kanban view renders groups using this configuration.

Usage

Call this after adding at least one view and the column you want to group by. Used by the database preset to group Database 2–Database 10 by their second column.

Code Reference

Source Location

  • Repository: Open-Agent
  • File: blocksuite/affine/data-view/src/core/group-by/trait.ts (GroupTrait L67-342, changeGroup L222-241, groupTraitKey L344); usage in blocksuite/playground/apps/starter/data/database.ts (L65-69); traitGet at blocksuite/affine/data-view/src/core/view-manager/single-view.ts (L278-280)

Signature

class GroupTrait {
  changeGroup(columnId: string | undefined): void;
  // ...changeCardSort, changeGroupSort, moveCardTo, moveGroupTo, updateValue, etc.
}

export const groupTraitKey: TraitKey<GroupTrait>;

// Retrieval:
const groupTrait = viewManager.currentView$.value?.traitGet(groupTraitKey);
groupTrait?.changeGroup(columnId);

Import

import { groupTraitKey } from '@blocksuite/data-view';
// groupTrait is obtained via viewManager.currentView$.value?.traitGet(groupTraitKey)

I/O Contract

Inputs

Name Type Required Description
columnId undefined Yes The property column id to group by; undefined clears grouping

Outputs

Name Type Description
(void) void The view's group-by setting is updated via ops.groupBySet

Usage Examples

Group by the Second Column

import { groupTraitKey } from '@blocksuite/data-view';

const groupTrait = datasource.viewManager.currentView$.value?.traitGet(groupTraitKey);
groupTrait?.changeGroup(database.props.columns[1].id);

// The view now groups rows by the selected column.

Clear Grouping

groupTrait?.changeGroup(undefined);

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment