Fields
Fields define the schema of a Base table. Each field has a type, configuration, default value, and capabilities such as sorting, filtering, grouping, or card display.
Add fields
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' }, ], }, }, },)Update fields
TypeScript
priority.setName('Impact')priority.update({ description: 'Business priority' })priority.setConfig({ options: [ { id: 'p0', name: 'P0', color: '#dc2626' }, { id: 'p1', name: 'P1', color: '#f97316' }, ],})Change field type
TypeScript
priority.changeType(univerAPI.Enum.BaseFieldType.Text, {})Changing a field type may normalize existing values. Validate data in your application before applying schema changes to production tables.
How is this guide?