フィールド
フィールドは Base テーブルのスキーマを定義します。各フィールドには、型、設定、デフォルト値のほか、並べ替え、フィルタリング、グループ化、カード表示などの機能があります。
フィールドを追加する
TypeScript
const table = base.getTableById('tasks')if (!table) throw new Error('Tasks table not found')const title = table.addField('Title', univerAPI.Enum.BaseFieldType.Text)const priority = table.addField( 'Priority', univerAPI.Enum.BaseFieldType.SingleSelect, { field: { config: { options: [ { id: 'high', name: 'High', color: '#ef4444' }, { id: 'low', name: 'Low', color: '#22c55e' }, ], }, }, },)フィールドを更新する
TypeScript
priority.setName('Impact')priority.update({ description: 'Business priority' })priority.setConfig({ options: [ { id: 'p0', name: 'P0', color: '#dc2626' }, { id: 'p1', name: 'P1', color: '#f97316' }, ],})フィールドの型を変更する
TypeScript
priority.changeType(univerAPI.Enum.BaseFieldType.Text, {})フィールドの型を変更すると、既存の値が正規化される場合があります。本番環境のテーブルにスキーマの変更を適用する前に、アプリケーションでデータを検証してください。
このガイドはいかがですか?