Table Blocks in Vue Block Editor component

20 Dec 202517 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.

<template>
  <div id='container'>
    <ejs-blockeditor :blocks="blocksData"></ejs-blockeditor>
  </div>
</template>

<script setup>
import { BlockEditorComponent as EjsBlockeditor, ContentType, BlockType } from "@syncfusion/ej2-vue-blockeditor";

const blocksData = [
      {
          blockType: BlockType.Table,
          properties: {
              columns: [{ id: 'col1', headerText: 'Column 1' }, { id: 'col2', headerText: 'Column 2' }],
              rows: [
                  {
                      cells: [
                          {
                              columnId: 'col1',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 1' }] }]
                          },
                          {
                              columnId: 'col2',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 2' }] }]
                          }
                      ]
                  },
                  {
                      cells: [
                          {
                              columnId: 'col1',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 3' }] }]
                          },
                          {
                              columnId: 'col2',
                              blocks: [{ 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.'
              }
          ]
      }]

</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-popups/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-buttons/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-navigations/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-dropdowns/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-inputs/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-blockeditor/styles/fluent2.css';
</style>
<template>
  <div id='container'>
    <ejs-blockeditor :blocks="blocksData"></ejs-blockeditor>
  </div>
</template>

<script>
import { BlockEditorComponent, ContentType, BlockType } from "@syncfusion/ej2-vue-blockeditor";

export default {
  components: {
    'ejs-blockeditor': BlockEditorComponent,
  },
  data: function () {
    return {
      blocksData: [
      {
          blockType: BlockType.Table,
          properties: {
              columns: [{ id: 'col1', headerText: 'Column 1' }, { id: 'col2', headerText: 'Column 2' }],
              rows: [
                  {
                      cells: [
                          {
                              columnId: 'col1',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 1' }] }]
                          },
                          {
                              columnId: 'col2',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 2' }] }]
                          }
                      ]
                  },
                  {
                      cells: [
                          {
                              columnId: 'col1',
                              blocks: [{ blockType: 'Paragraph', content: [{ contentType: ContentType.Text, content: 'Cell 3' }] }]
                          },
                          {
                              columnId: 'col2',
                              blocks: [{ 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.'
              }
          ]
      }]
    };
  },
  methods: {
    
  }
};
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-popups/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-buttons/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-navigations/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-dropdowns/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-inputs/styles/fluent2.css';
  @import '../node_modules/@syncfusion/ej2-blockeditor/styles/fluent2.css';
</style>