This page demonstrates how to embed data tables directly from MDX using the <Datatable src="..." /> component.
Basic Usage
All you need is two files:
| File | Role |
|---|---|
src/data/books.json | Data array |
src/data/books-table.json | Column, filter, and transform definitions |
Then, just add one line to your MDX to display the table.
<Datatable src="books" />
src specifies the filename without extension. It will load src/data/books.json and src/data/books-table.json.Demo
全 8 件
| タイトル | 著者 | 出版年 | ジャンル | 評価 | タグ |
|---|---|---|---|---|---|
| 達人プログラマー | David Thomas, Andrew Hunt | 2020 | 技術書 | ★★★★★ | プログラミングキャリア |
| Clean Code | Robert C. Martin | 2009 | 技術書 | ★★★★★ | プログラミング設計 |
| イシューからはじめよ | 安宅和人 | 2010 | ビジネス | ★★★★★ | 思考法問題解決 |
| FACTFULNESS | Hans Rosling | 2018 | ノンフィクション | ★★★★★ | データ思考法 |
| Designing Data-Intensive Applications | Martin Kleppmann | 2017 | 技術書 | ★★★★★ | 分散システムデータベース |
| エッセンシャル思考 | Greg McKeown | 2014 | ビジネス | ★★★★☆ | 生産性思考法 |
| Design Patterns | GoF | 1994 | 技術書 | ★★★★☆ | プログラミング設計 |
| ゼロ・トゥ・ワン | Peter Thiel | 2014 | ビジネス | ★★★☆☆ | スタートアップビジネス |
Multiple Tables on the Same Page
When placing multiple tables on the same page, specify an id to distinguish them.
<Datatable src="books" id="books-second" />
Table Definition File (-table.json) Structure
{
"columns": [
{ "key": "title", "label": "Title", "align": "left", "html": true },
{ "key": "rating", "label": "Rating", "align": "center", "html": true }
],
"filters": [
{ "key": "genre", "label": "Genre" },
{ "key": "tags", "label": "Tags", "split": "," }
],
"defaultSort": "rating",
"defaultAsc": false,
"transform": {
"rating": { "type": "stars", "max": 5 },
"genre": { "type": "badge", "colors": { "Technical": { "bg": "#dbeafe", "color": "#1d4ed8" } } },
"tags": { "type": "tags" },
"title": { "type": "link", "hrefField": "id", "basePath": "/books/" }
}
}
Available Cell Transformations in transform
| Type | Description |
|---|---|
stars | Display number as ★☆. Specify maximum with max. |
badge | Specify background and text color per key with colors map. |
tags | Display array or comma-separated string as tag chips. |
link | Turn content into a link using hrefField for the URL and basePath as prefix. |
To add more data, simply add items to
src/data/books.json. You can increase data without changing the table definition.Related Pages
- Sample: Basic Features — Basic Markdown features
- Sample: Shortcode Reference — List of all shortcodes