|
| 1 | +--- |
| 2 | +title: Advanced Tables |
| 3 | +description: This section explains how to use more advanced features of tables. |
| 4 | +imageTitle: Advanced Tables |
| 5 | +--- |
| 6 | + |
| 7 | +import { Example } from "@/components/example"; |
| 8 | + |
| 9 | +# Advanced Tables |
| 10 | + |
| 11 | +Tables by default are a simple way to display data in a grid. But, BlockNote also supports more advanced features like: |
| 12 | + |
| 13 | +- Split cells |
| 14 | +- Cell background color |
| 15 | +- Cell text color |
| 16 | +- Header rows & columns |
| 17 | + |
| 18 | +To keep the default table experience easy to use, these features are disabled by default. |
| 19 | + |
| 20 | +You can enable them by passing the `tables` option when creating the editor. |
| 21 | + |
| 22 | +```ts |
| 23 | +const editor = new BlockNoteEditor({ |
| 24 | + tables: { |
| 25 | + splitCells: true, |
| 26 | + cellBackgroundColor: true, |
| 27 | + cellTextColor: true, |
| 28 | + headers: true, |
| 29 | + }, |
| 30 | +}); |
| 31 | +``` |
| 32 | + |
| 33 | +You can choose to enable only certain features, or none at all. Giving you the flexibility to use tables how you need in your app. |
| 34 | + |
| 35 | +Here's an example of the editor with all features enabled: |
| 36 | + |
| 37 | +<Example name="ui-components/advanced-tables" /> |
| 38 | + |
| 39 | +## Cell background color |
| 40 | + |
| 41 | +To enable cell background color, you need to pass `cellBackgroundColor: true` to the `tables` option. |
| 42 | + |
| 43 | +```ts |
| 44 | +const editor = new BlockNoteEditor({ |
| 45 | + tables: { |
| 46 | + cellBackgroundColor: true, |
| 47 | + }, |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +## Cell text color |
| 52 | + |
| 53 | +To enable cell text color, you need to pass `cellTextColor: true` to the `tables` option. |
| 54 | + |
| 55 | +```ts |
| 56 | +const editor = new BlockNoteEditor({ |
| 57 | + tables: { |
| 58 | + cellTextColor: true, |
| 59 | + }, |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | + |
| 64 | +## Header rows & columns |
| 65 | + |
| 66 | +BlockNote supports headers in tables, which are the first row and/or first column of a table. |
| 67 | + |
| 68 | +To enable it, you need to pass `headers: true` to the `tables` option. |
| 69 | + |
| 70 | +```ts |
| 71 | +const editor = new BlockNoteEditor({ |
| 72 | + tables: { |
| 73 | + headers: true, |
| 74 | + }, |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +## Split cells |
| 79 | + |
| 80 | +Splitting and merging cells is a common feature of more advanced table editors. |
| 81 | + |
| 82 | +To enable it, you need to pass `splitCells: true` to the `tables` option. |
| 83 | + |
| 84 | +```ts |
| 85 | +const editor = new BlockNoteEditor({ |
| 86 | + tables: { |
| 87 | + splitCells: true, |
| 88 | + }, |
| 89 | +}); |
| 90 | +``` |
| 91 | + |
| 92 | + |
0 commit comments