2020-08-04 22:22:47 +02:00
|
|
|
|
---
|
|
|
|
|
template: overrides/main.html
|
2021-12-16 17:08:57 +01:00
|
|
|
|
icon: material/table-edit
|
2020-08-04 22:22:47 +02:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Data tables
|
|
|
|
|
|
|
|
|
|
Material for MkDocs defines default styles for data tables – an excellent way
|
|
|
|
|
of rendering tabular data in project documentation. Furthermore, customizations
|
2021-10-03 18:29:50 +02:00
|
|
|
|
like [sortable tables] can be achieved with a third-party library and some
|
|
|
|
|
[additional JavaScript].
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
[sortable tables]: #sortable-tables
|
|
|
|
|
[additional JavaScript]: ../customization.md#additional-javascript
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
This configuration enables Markdown table support, which should normally be
|
|
|
|
|
enabled by default, but to be sure, add the following lines to `mkdocs.yml`:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
markdown_extensions:
|
|
|
|
|
- tables
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
See additional configuration options:
|
|
|
|
|
|
|
|
|
|
- [Tables]
|
|
|
|
|
|
|
|
|
|
[Tables]: ../setup/extensions/python-markdown.md#tables
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
Data tables can be used at any position in your project documentation and can
|
|
|
|
|
contain arbitrary Markdown, including inline code blocks, as well as [icons and
|
2021-10-03 18:29:50 +02:00
|
|
|
|
emojis].
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------- | ------------------------------------ |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------- | ------------------------------------ |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
[icons and emojis]: icons-emojis.md
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
### Column alignment
|
|
|
|
|
|
|
|
|
|
If you want to align a specific column to the `left`, `center` or `right`, you
|
2021-10-03 18:29:50 +02:00
|
|
|
|
can use the [regular Markdown syntax] placing `:` characters at the beginning
|
2020-08-04 22:22:47 +02:00
|
|
|
|
and/or end of the divider.
|
|
|
|
|
|
|
|
|
|
=== "Left"
|
|
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
|
|
``` markdown hl_lines="2"
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| :---------- | :----------------------------------- |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| :---------- | :----------------------------------- |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
|
|
|
|
|
=== "Center"
|
|
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
|
|
``` markdown hl_lines="2"
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| :---------: | :----------------------------------: |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| :---------: | :----------------------------------: |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
|
|
|
|
|
=== "Right"
|
|
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
|
|
``` markdown hl_lines="2"
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------: | -----------------------------------: |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------: | -----------------------------------: |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
[regular Markdown syntax]: https://www.markdownguide.org/extended-syntax/#tables
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
## Customization
|
|
|
|
|
|
|
|
|
|
### Sortable tables
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
If you want to make data tables sortable, you can add [tablesort], which is
|
2020-08-06 08:59:27 +02:00
|
|
|
|
natively integrated with Material for MkDocs and will also work with [instant
|
2021-10-03 18:29:50 +02:00
|
|
|
|
loading] via [additional JavaScript]:
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
2021-10-10 12:19:14 +02:00
|
|
|
|
=== ":octicons-file-code-16: docs/javascripts/tablesort.js"
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
``` js
|
2021-02-22 22:27:30 +01:00
|
|
|
|
document$.subscribe(function() {
|
2021-12-06 23:51:34 +01:00
|
|
|
|
var tables = document.querySelectorAll("article table:not([class])")
|
2020-08-04 22:22:47 +02:00
|
|
|
|
tables.forEach(function(table) {
|
|
|
|
|
new Tablesort(table)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
=== ":octicons-file-code-16: mkdocs.yml"
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra_javascript:
|
|
|
|
|
- https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js
|
2021-10-10 12:19:14 +02:00
|
|
|
|
- javascripts/tablesort.js
|
2020-08-04 22:22:47 +02:00
|
|
|
|
```
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
Note that [tablesort] provides alternative comparison implementations like
|
|
|
|
|
numbers, filesizes, dates and month names. See the [tablesort documentation]
|
|
|
|
|
[tablesort] for more information.
|
2020-08-04 22:22:47 +02:00
|
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------- | ------------------------------------ |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
|
| ----------- | ------------------------------------ |
|
|
|
|
|
| `GET` | :material-check: Fetch resource |
|
|
|
|
|
| `PUT` | :material-check-all: Update resource |
|
|
|
|
|
| `DELETE` | :material-close: Delete resource |
|
|
|
|
|
|
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
var tables = document.querySelectorAll("article table")
|
|
|
|
|
new Tablesort(tables.item(tables.length - 1));
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-10-03 18:29:50 +02:00
|
|
|
|
[tablesort]: http://tristen.ca/tablesort/demo/
|
|
|
|
|
[instant loading]: ../setup/setting-up-navigation.md#instant-loading
|