我想做一個 Rowspan 我表的第一列。
我的當前表如下所示:
| 型別 | 顏色 | 編號 |
|---|---|---|
| 車 | 紅色的 | 1 |
| 車 | 黑色的 | 2 |
| 車 | 黑色的 | 3 |
| 自行車 | 黃色的 | 4 |
| 自行車 | 綠色的 | 5 |
| 自行車 | 黃色的 | 6 |
我想要的是合并所有具有相同型別的行。對于這個例子,我應該在Type Column中 只有兩行;汽車和自行車。我知道如何進行崩潰,但問題是我正在從資料庫中獲取我的表,如下所示:
<table class="table table-striped table-bordered " style="display:inline-table;">
<thead>
<tr >
<th class="col-1">
Type
</th>
<th class="col-2">
Color
</th>
<th class="col-2">
Num
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@item.Type
</td>
<td>
@item.Color
</td>
<td>
@item.Num
</td>
</tr>
}
</tbody>
</table>
uj5u.com熱心網友回復:
分組資料:
<tbody>
@foreach (var group in Model.GroupBy(i => i.Type))
{
var items = group.ToList();
<tr>
<td rowspan="@items.Count">@group.Key</td>
<td>@items[0].Color</td>
<td>@items[0].Num</td>
</tr>
@for (int index = 1; index < items.Count; index )
{
<tr>
<td>@items[index].Color</td>
<td>@items[index].Num</td>
</tr>
}
}
</tbody>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/428920.html
標籤:javascript C# html 林克 html表
