Multimarkdown Tables
You can use Multimarkdown syntax for tables. The following shows a sample:
| Priority apples | Second priority | Third priority |
|-------|--------|---------|
| ambrosia | gala | red delicious |
| pink lady | jazz | macintosh |
| honeycrisp | granny smith | fuji |
Result:
Priority apples | Second priority | Third priority |
---|---|---|
ambrosia | gala | red delicious |
pink lady | jazz | macintosh |
honeycrisp | granny smith | fuji |
<br/><br/>
.HTML Tables
If you need a more sophisticated table syntax, use HTML syntax for the table. Although you’re using HTML, you can use Markdown inside the table cells by adding markdown="span"
as an attribute for the td
tag, as shown in the following table. You can also control the column widths.
<table>
<colgroup>
<col width="30%" />
<col width="70%" />
</colgroup>
<thead>
<tr class="header">
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td markdown="span">First column **fields**</td>
<td markdown="span">Some descriptive text. This is a markdown link to [Google](http://google.com). Or see [some link][mydoc_tags].</td>
</tr>
<tr>
<td markdown="span">Second column **fields**</td>
<td markdown="span">Some more descriptive text.
</td>
</tr>
</tbody>
</table>
Result:
Field | Description |
---|---|
First column fields | Some descriptive text. This is a markdown link to Google. Or see some link. |
Second column fields | Some more descriptive text. |
jQuery datables
You also have the option of using a jQuery datatable, which gives you some more options. If you want to use a jQuery datatable, then add datatable: true
in a page’s frontmatter. This will load the right jQuery datatable scripts for the table on that page only (rather than loading the scripts on every page of the site.)
Also, you need to add this script to trigger the jQuery table on your page:
<script>
$(document).ready(function(){
$('table.display').DataTable( {
paging: true,
stateSave: true,
searching: true
}
);
});
</script>
The available options for the datable are described in the datatable documentation, which is excellent.
Additionally, you must add a class of display
to your tables. (You can change the class, but then you’ll need to change the trigger above from table.display
to whatever class you want to you. You might have different triggers with different options for different tables.)
Since Markdown doesn’t allow you to add classes to tables, you’ll need to use HTML for any datatables. Here’s an example:
<table id="sampleTable" class="display">
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Type</th>
<th>Default Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Parameter 1</td>
<td>Sample description
</td>
<td>Sample type</td>
<td>Sample default value</td>
</tr>
<tr>
<td>Parameter 2</td>
<td>Sample description
</td>
<td>Sample type</td>
<td>Sample default value</td>
</tr>
<tr>
<td>Parameter 3</td>
<td>Sample description
</td>
<td>Sample type</td>
<td>Sample default value</td>
</tr>
<tr>
<td>Parameter 4</td>
<td>Sample description
</td>
<td>Sample type</td>
<td>Sample default value</td>
</tr>
</tbody>
</table>
This renders to the following:
Notice a few features:
- You can keyword search the table. When you type a word, the table filters to match your word.
- You can sort the column order.
- You can page the results so that you show only a certain number of values on the first page and then require users to click next to see more entries.
Read more of the datatable documentation to get a sense of the options you can configure. You should probably only use datatables when you have long, massive tables full of information.