Table Blocks in Angular Block Editor component
18 Dec 202511 minutes to read
The Syncfusion Block Editor allows you to render structured data in rows and columns by setting the block’s blockType property to Table. You can customize the table layout, header, row numbers, and define columns and rows using the properties property.
Configure Table Block
For Table blocks, you can configure layout and structure using the properties property. This property supports the following options:
| Property | Description | Default Value |
|---|---|---|
| width | Specifies the display width of the table. | 100% |
| enableHeader | Specifies whether to enable header for the table. | true |
| enableRowNumbers | Specifies whether to enable row numbers for the table. | true |
| readOnly | Specifies whether to render the table in read-only mode, disabling edits. | false |
| columns | Defines the columns of the table, including their types and headers. | [] |
| rows | Defines the rows of the table, each containing cells tied to columns. | [] |
BlockType & Properties
The following example demonstrates how to pre-configure a Table block in the editor.
// Adding an Table block
{
blockType: BlockType.Table,
properties: {
columns: [{ id: 'col1', headerText: 'Column 1' }, { id: 'col2', headerText: 'Column 2' }],
rows: [
{
cells: [
{
columnId: 'col1',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 1' }] }]
},
{
columnId: 'col2',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 2' }] }]
}
]
},
{
cells: [
{
columnId: 'col1',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 3' }] }]
},
{
columnId: 'col2',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 4' }] }]
}
]
}
]
}
}This sample demonstrates the configuration of the Table block in the Block Editor.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Component } from '@angular/core';
import { BlockEditorModule } from "@syncfusion/ej2-angular-blockeditor";
import { BlockModel, ContentType, BlockType } from "@syncfusion/ej2-blockeditor";
@Component({
imports: [FormsModule, ReactiveFormsModule, BlockEditorModule],
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
public blocksData: BlockModel[] = [
{
blockType: BlockType.Table,
properties: {
columns: [{ id: 'col1', headerText: 'Column 1' }, { id: 'col2', headerText: 'Column 2' }],
rows: [
{
cells: [
{
columnId: 'col1',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 1' }] }]
},
{
columnId: 'col2',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 2' }] }]
}
]
},
{
cells: [
{
columnId: 'col1',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 3' }] }]
},
{
columnId: 'col2',
blocks: [{ blockType: BlockType.Paragraph, content: [{ contentType: ContentType.Text, content: 'Cell 4' }] }]
}
]
}
]
}
},
{
blockType: 'Paragraph',
content: [
{
contentType: ContentType.Text,
content: 'You can customize the table further by configuring properties like width, enableHeader to show a header row, enableRowNumbers to display row indices, and readOnly to prevent edits.'
}
]
}];
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));<div id="container">
<ejs-blockeditor id="blockeditor" [blocks]="blocksData" />
</div>