WebGrid
在 MVC 中使用时是否可以对列进行分组?我只能找到一个使用子网格的示例,但它会为每个单元格重复子标题,例如Razor Nested WebGrid:
@{
var data = Enumerable.Range(0, 10).Select(i => new { Index = i, SubItems = new object[] { new { A = "A" + i, B = "B" + (i * i) } } }).ToArray();
WebGrid topGrid = new WebGrid(data);
}
@topGrid.GetHtml(columns:
topGrid.Columns(
topGrid.Column("Index"),
topGrid.Column("SubItems", format: (item) =>
{
WebGrid subGrid = subGrid = new WebGrid(item.SubItems);
return subGrid.GetHtml(
columns: subGrid.Columns(
subGrid.Column("A"),
subGrid.Column("B")
)
);
})
)
)
这将导致这样的事情
____________________
| index | sub item|
|_______|__________|
| 0 | A B |
| | 1 2 |
|_______|__________|
| 1 | A B |
| | 1 2 |
|_______|__________|
| 2 | A B |
| | 1 2 |
|_______|__________|
但我正在寻找的是:
____________________
| index | sub item|
|_______|__________|
| | A | B |
|_______|____|_____|
| 0 | 1 | 2 |
| 1 | 1 | 2 |
| 2 | 1 | 2 |
|_______|____|_____|