|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: displaying beatiful tables with Bootstrap Tables |
| 4 | +date: 2023-03-20 14:37:00-0400 |
| 5 | +description: an example of how to use Bootstrap Tables |
| 6 | +categories: sample-posts |
| 7 | +giscus_comments: true |
| 8 | +related_posts: true |
| 9 | +datatable: true |
| 10 | +--- |
| 11 | + |
| 12 | +Using markdown to display tables is easy. Just use the following syntax: |
| 13 | + |
| 14 | +```markdown |
| 15 | +| Left aligned | Center aligned | Right aligned | |
| 16 | +| :----------- | :------------: | ------------: | |
| 17 | +| Left 1 | center 1 | right 1 | |
| 18 | +| Left 2 | center 2 | right 2 | |
| 19 | +| Left 3 | center 3 | right 3 | |
| 20 | +``` |
| 21 | + |
| 22 | +That will generate: |
| 23 | + |
| 24 | +| Left aligned | Center aligned | Right aligned | |
| 25 | +| :----------- | :------------: | ------------: | |
| 26 | +| Left 1 | center 1 | right 1 | |
| 27 | +| Left 2 | center 2 | right 2 | |
| 28 | +| Left 3 | center 3 | right 3 | |
| 29 | + |
| 30 | +<p></p> |
| 31 | + |
| 32 | +It is also possible to use HTML to display tables. For example, the following HTML code will display a table with [Bootstrap Table](https://bootstrap-table.com/), loaded from a JSON file: |
| 33 | + |
| 34 | +{% raw %} |
| 35 | +```html |
| 36 | +<table |
| 37 | + id="table" |
| 38 | + data-toggle="table" |
| 39 | + data-url="{{ '/assets/json/table_data.json' | relative_url }}"> |
| 40 | + <thead> |
| 41 | + <tr> |
| 42 | + <th data-field="id">ID</th> |
| 43 | + <th data-field="name">Item Name</th> |
| 44 | + <th data-field="price">Item Price</th> |
| 45 | + </tr> |
| 46 | + </thead> |
| 47 | +</table> |
| 48 | +``` |
| 49 | +{% endraw %} |
| 50 | + |
| 51 | +<table |
| 52 | + data-toggle="table" |
| 53 | + data-url="{{ '/assets/json/table_data.json' | relative_url }}"> |
| 54 | + <thead> |
| 55 | + <tr> |
| 56 | + <th data-field="id">ID</th> |
| 57 | + <th data-field="name">Item Name</th> |
| 58 | + <th data-field="price">Item Price</th> |
| 59 | + </tr> |
| 60 | + </thead> |
| 61 | +</table> |
| 62 | + |
| 63 | +<p></p> |
| 64 | + |
| 65 | +By using [Bootstrap Table](https://bootstrap-table.com/) it is possible to create pretty complex tables, with pagination, search, and more. For example, the following HTML code will display a table, loaded from a JSON file, with pagination, search, checkboxes, and header/content alignment. For more information, check the [documentation](https://examples.bootstrap-table.com/index.html). |
| 66 | + |
| 67 | +{% raw %} |
| 68 | +```html |
| 69 | +<table |
| 70 | + data-click-to-select="true" |
| 71 | + data-height="460" |
| 72 | + data-pagination="true" |
| 73 | + data-search="true" |
| 74 | + data-toggle="table" |
| 75 | + data-url="{{ '/assets/json/table_data.json' | relative_url }}"> |
| 76 | + <thead> |
| 77 | + <tr> |
| 78 | + <th data-checkbox="true"></th> |
| 79 | + <th data-field="id" data-halign="left" data-align="center" data-sortable="true">ID</th> |
| 80 | + <th data-field="name" data-halign="center" data-align="right" data-sortable="true">Item Name</th> |
| 81 | + <th data-field="price" data-halign="right" data-align="left" data-sortable="true">Item Price</th> |
| 82 | + </tr> |
| 83 | + </thead> |
| 84 | +</table> |
| 85 | +``` |
| 86 | +{% endraw %} |
| 87 | + |
| 88 | +<table |
| 89 | + data-click-to-select="true" |
| 90 | + data-height="460" |
| 91 | + data-pagination="true" |
| 92 | + data-search="true" |
| 93 | + data-toggle="table" |
| 94 | + data-url="{{ '/assets/json/table_data.json' | relative_url }}"> |
| 95 | + <thead> |
| 96 | + <tr> |
| 97 | + <th data-checkbox="true"></th> |
| 98 | + <th data-field="id" data-halign="left" data-align="center" data-sortable="true">ID</th> |
| 99 | + <th data-field="name" data-halign="center" data-align="right" data-sortable="true">Item Name</th> |
| 100 | + <th data-field="price" data-halign="right" data-align="left" data-sortable="true">Item Price</th> |
| 101 | + </tr> |
| 102 | + </thead> |
| 103 | +</table> |
0 commit comments