Implementation:AFK surf Open agent DataSource CellValueChange
| Knowledge Sources | |
|---|---|
| Domains | Database, Data_View, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Concrete API for writing a cell value into a database row/property pair through the DataSource adapter.
Description
datasource.cellValueChange is the write primitive for database cells. Given a row id (a child block id under the database), a property id (a column id from propertyAdd), and a value, it persists the value into the yjs cell map. Rich-text columns take a Text instance; other typed columns take primitives (number, boolean) or option-id arrays (multi-select). Always use this method instead of mutating the block model's cells map directly so the data-view reactivity stays in sync.
Usage
Call this after adding properties and row blocks. Used to populate the rich-text column (and any other typed column) for each row block in the database preset.
Code Reference
Source Location
- Repository: Open-Agent
- File: interface at blocksuite/affine/data-view/src/core/data-source/base.ts (L28, abstract L140-150); usage in blocksuite/playground/apps/starter/data/database.ts (L87-92, L103-108)
Signature
interface DataSource {
cellValueGet(rowId: string, propertyId: string): unknown;
cellValueGet$(rowId: string, propertyId: string): ReadonlySignal<unknown | undefined>;
cellValueChange(rowId: string, propertyId: string, value: unknown): void;
}
Import
// cellValueChange is a method on the datasource instance:
const datasource = new DatabaseBlockDataSource(database);
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| rowId | string | Yes | The row block id (a child block of the database) |
| propertyId | string | Yes | The column id returned by propertyAdd |
| value | unknown | Yes | Text for rich-text columns; primitives/arrays for others |
Outputs
| Name | Type | Description |
|---|---|---|
| (void) | void | The cell value is persisted; reactive signals update |
Usage Examples
Populate a Rich-Text Cell for Each Row
const richTextId = datasource.propertyAdd('end', {
type: databaseBlockProperties.richTextColumnConfig.type,
name: 'Rich Text',
});
const rowId = store.addBlock(
'affine:paragraph',
{ type: 'text', text: new Text('Row content') },
databaseId
);
datasource.cellValueChange(rowId, richTextId, new Text('Row content'));
Read a Cell Reactively
const cellSignal = datasource.cellValueGet$(rowId, richTextId);
console.log(cellSignal.value); // current value, updates reactively