forked from weldr/weldr.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvtable.html
More file actions
80 lines (68 loc) · 2.21 KB
/
Copy pathcsvtable.html
File metadata and controls
80 lines (68 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{% comment %}
Include this to render some CSV data into a static, sortable HTML table.
Example:
{% capture csvdata %}
word,count,prefix,suffix,meaning
devel,4407,0,4407,file type
[...]
{% endcapture %}
{% include csvtable.html data=csvdata %}
Or, if you have some data without quotes:
{% include csvtable.html
height="480px"
data="
word,count,prefix,suffix,meaning
devel,4407,0,4407,file-type
" %}
Required parameters:
data=var csv data to render
Optional parameters:
sort=false do not make the table sortable
limit=NUM only use the first NUM rows of data
height="SIZE" put the table in a scrollable <div> with "height: SIZE;"
tableid="ID" set "id=ID" on the enclosing <table> (default: "csvtable")
caption="STR" add a caption/header to the table
FIXME: handle quoting in CSV
TODO: show sort arrows on sortable columns
TOOD: restrict which columns to sort
TODO: pagination and searching
TODO: link to static CSV file
{% endcomment %}
{% assign rows = include.data | strip | newline_to_br | split: '<br />' %}
{% assign columns = rows | first | split: ',' %}
{% capture tableid %}{{ include.tableid | default: "csvtable" }}{% endcapture %}
{% if include.limit > 0 %}{% assign limit = include.limit %}{% endif %}
<div id="{{ tableid }}-wrap" style="height: {{ include.height | default: "auto" }}; overflow: auto;">
<table id="{{ tableid }}">
<caption>{{ include.caption }}</caption>
<thead>
<tr>
{%- for colname in columns -%}
<th><span class="sort" data-sort="{{ colname }}">{{ colname }}</span></th>
{%- endfor -%}
</tr>
</thead>
<tbody class="list">
{% for row in rows offset:1 limit:{{limit}} %}{% assign items = row | split: ',' %}
<tr>
{%- for item in items -%}
<td class="{{ columns[forloop.index0] }}">{{- item | strip -}}</td>
{%- endfor -%}
</tr>
{%- endfor -%}
</tbody>
{% unless include.sort == false %}
<style>
.sort { cursor: pointer; }
</style>
<script src="{{ "/assets/js/list.min.js" | relative_url }}"></script>
<script>
var options = {
valueNames: {{ columns | jsonify }},
indexAsync: true
};
var tableList = new List("{{ tableid }}", options);
</script>
{% endunless %}
</table>
</div>