data-table
卡片中的数字表格。在窄屏上,左右滚动卡片即可看到每一列。行标题始终可见。
按数字排序
<div rst-box-head >
<h2 id ="sales-h" >按周统计的销量</h2 >
</div >
<div rst-card rst-table-scroll ="" tabindex ="0" role ="region" aria-labelledby ="sales-h" >
<table rst-table ="" aria-labelledby ="sales-h" >
<thead >
<tr >
<th scope ="col" >周</th >
<th scope ="col" rst-num aria-sort ="descending" >
<a href ="/sales?sort=sold&dir=asc" >售出<svg class ="icon" viewBox ="0 0 24 24" fill ="none" stroke ="currentColor" stroke-width ="2" stroke-linecap ="round" stroke-linejoin ="round" aria-hidden ="true" ><path d ="m6 9 6 6 6-6" /></svg ></a >
</th >
<th scope ="col" rst-num >
<a href ="/sales?sort=target&dir=desc" >目标<svg class ="icon" viewBox ="0 0 24 24" fill ="none" stroke ="currentColor" stroke-width ="2" stroke-linecap ="round" stroke-linejoin ="round" aria-hidden ="true" ><path d ="m6 9 6 6 6-6" /></svg ></a >
</th >
<th scope ="col" rst-num >退款</th >
</tr >
</thead >
<tbody >
<tr >
<th scope ="row" >3</th >
<td rst-num >260</td >
<td rst-num >600</td >
<td rst-num >5</td >
</tr >
<tr >
<th scope ="row" >4</th >
<td rst-num >240</td >
<td rst-num >600</td >
<td rst-num >1</td >
</tr >
<tr >
<th scope ="row" >2</th >
<td rst-num >180</td >
<td rst-num >600</td >
<td rst-num >0</td >
</tr >
<tr >
<th scope ="row" >1</th >
<td rst-num >120</td >
<td rst-num >600</td >
<td rst-num >2</td >
</tr >
</tbody >
<tfoot >
<tr >
<th scope ="row" >合计</th >
<td rst-num >800</td >
<td rst-num >2,400</td >
<td rst-num >8</td >
</tr >
</tfoot >
</table >
</div >
{{ template "data-table" dict
"Columns" (list
(dict "Label" "周" )
(dict "Href" "/sales?sort=sold&dir=asc" "Label" "售出" "Num" true "Sort" "descending" )
(dict "Href" "/sales?sort=target&dir=desc" "Label" "目标" "Num" true )
(dict "Label" "退款" "Num" true ))
"Foot" (list "合计" 800 2400 8)
"ID" "sales"
"Rows" (list (list 3 260 600 5) (list 4 240 600 1) (list 2 180 600 0) (list 1 120 600 2))
"Title" "按周统计的销量" }}
把列标题链接到排序后的列表,再给这一列设置 Sort。用 Num 标出数字列。
紧凑,表头固定
<div rst-box-head >
<h2 id ="sales-dense-h" >按周统计的销量</h2 >
</div >
<div rst-card rst-table-scroll ="bounded" tabindex ="0" role ="region" aria-labelledby ="sales-dense-h" >
<table rst-table ="dense" aria-labelledby ="sales-dense-h" >
<thead >
<tr >
<th scope ="col" >周</th >
<th scope ="col" rst-num >售出</th >
<th scope ="col" rst-num >目标</th >
<th scope ="col" rst-num >退款</th >
</tr >
</thead >
<tbody >
<tr >
<th scope ="row" >1</th >
<td rst-num >120</td >
<td rst-num >600</td >
<td rst-num >2</td >
</tr >
<tr >
<th scope ="row" >2</th >
<td rst-num >180</td >
<td rst-num >600</td >
<td rst-num >0</td >
</tr >
<tr >
<th scope ="row" >3</th >
<td rst-num >260</td >
<td rst-num >600</td >
<td rst-num >5</td >
</tr >
<tr >
<th scope ="row" >4</th >
<td rst-num >240</td >
<td rst-num >600</td >
<td rst-num >1</td >
</tr >
<tr >
<th scope ="row" >5</th >
<td rst-num >390</td >
<td rst-num >600</td >
<td rst-num >3</td >
</tr >
<tr >
<th scope ="row" >6</th >
<td rst-num >610</td >
<td rst-num >600</td >
<td rst-num >4</td >
</tr >
<tr >
<th scope ="row" >7</th >
<td rst-num >650</td >
<td rst-num >600</td >
<td rst-num >0</td >
</tr >
<tr >
<th scope ="row" >8</th >
<td rst-num >690</td >
<td rst-num >600</td >
<td rst-num >2</td >
</tr >
</tbody >
</table >
</div >
{{ template "data-table" dict
"Bounded" true
"Columns" (list
(dict "Label" "周" )
(dict "Label" "售出" "Num" true )
(dict "Label" "目标" "Num" true )
(dict "Label" "退款" "Num" true ))
"Dense" true
"ID" "sales-dense"
"Rows" (list (list 1 120 600 2) (list 2 180 600 0) (list 3 260 600 5) (list 4 240 600 1) (list 5 390 600 3) (list 6 610 600 4) (list 7 650 600 0) (list 8 690 600 2))
"Title" "按周统计的销量" }}
Dense 让行更紧凑。Bounded 限制高度,滚动行时表头保持可见。
没有匹配的行
<div rst-box-head >
<h2 id ="sales-none-h" >按周统计的销量</h2 >
</div >
<div rst-card rst-table-scroll ="" tabindex ="0" role ="region" aria-labelledby ="sales-none-h" >
<table rst-table ="" aria-labelledby ="sales-none-h" >
<thead >
<tr >
<th scope ="col" >周</th >
<th scope ="col" rst-num >售出</th >
<th scope ="col" rst-num >目标</th >
<th scope ="col" rst-num >退款</th >
</tr >
</thead >
<tbody >
<tr rst-table-empty >
<td colspan ="4" >没有符合条件的周。</td >
</tr >
</tbody >
</table >
</div >
{{ template "data-table" dict
"Columns" (list
(dict "Label" "周" )
(dict "Label" "售出" "Num" true )
(dict "Label" "目标" "Num" true )
(dict "Label" "退款" "Num" true ))
"Empty" "没有符合条件的周。"
"ID" "sales-none"
"Title" "按周统计的销量" }}
没有行时,表头仍在,Empty 说明原因。