Implementation:AFK surf Open agent DataSource PropertyAdd
| Knowledge Sources | |
|---|---|
| Domains | Database, Data_View, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Concrete API for adding a typed property (column) to a data source at a given position, using a property type from a preset config.
Description
datasource.propertyAdd inserts a new column into the data source. It takes an InsertToPosition ('end' to append, or a numeric index) and an options bag carrying the property type string (from a property config's .type field) and a display name. The property type drives cell rendering, filter matching, group-by behavior, and conversions. Available property types come from two barrels: propertyPresets (multi-select, date, number, checkbox, progress, select, image, text) and databaseBlockProperties (rich-text and link columns specific to the database block).
Usage
Call this after wrapping a database with a DatabaseBlockDataSource and adding at least one view. Iterate over the preset configs to add a set of typed columns, or add a single column for a targeted use case.
Code Reference
Source Location
- Repository: Open-Agent
- File: interface at blocksuite/affine/data-view/src/core/data-source/base.ts (L62-68); usage in blocksuite/playground/apps/starter/data/database.ts (L48-64); preset barrel at blocksuite/affine/data-view/src/property-presets/index.ts (L13-22)
Signature
interface DataSource {
propertyAdd(
insertToPosition: InsertToPosition,
ops?: { type?: string; name?: string }
): string | undefined;
}
// Property preset barrel:
const propertyPresets = {
checkboxPropertyConfig,
datePropertyConfig,
imagePropertyConfig,
multiSelectPropertyConfig,
numberPropertyConfig,
progressPropertyConfig,
selectPropertyConfig,
textPropertyConfig,
};
Import
import { propertyPresets } from '@blocksuite/data-view/property-presets';
import { databaseBlockProperties } from '@blocksuite/affine/blocks/database';
// propertyAdd is a method on the datasource instance
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| insertToPosition | InsertToPosition | Yes | 'end' to append, or a numeric index |
| ops.type | string | Yes | Property type string, e.g. propertyPresets.multiSelectPropertyConfig.type |
| ops.name | string | No | Display name for the column |
Outputs
| Name | Type | Description |
|---|---|---|
| propertyId | undefined | The id of the new column; use it with cellValueChange |
Usage Examples
Add a Rich-Text and a Multi-Select Column
const richTextId = datasource.propertyAdd('end', {
type: databaseBlockProperties.richTextColumnConfig.type,
name: 'Rich Text',
});
datasource.propertyAdd('end', {
type: propertyPresets.multiSelectPropertyConfig.type,
name: propertyPresets.multiSelectPropertyConfig.config.name,
});
Iterate Over All Standard Presets
Object.values([
propertyPresets.multiSelectPropertyConfig,
propertyPresets.datePropertyConfig,
propertyPresets.numberPropertyConfig,
databaseBlockProperties.linkColumnConfig,
propertyPresets.checkboxPropertyConfig,
propertyPresets.progressPropertyConfig,
]).forEach(column => {
datasource.propertyAdd('end', { type: column.type, name: column.config.name });
});