Is it possible to group columns while using WebGrid
in MVC?
All i could find is a example of using a sub grid but it will repeat the sub headers for every cell like this 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")
)
);
})
)
)
this will result in something like this
____________________
| index | sub item|
|_______|__________|
| 0 | A B |
| | 1 2 |
|_______|__________|
| 1 | A B |
| | 1 2 |
|_______|__________|
| 2 | A B |
| | 1 2 |
|_______|__________|
but what i am looking for is:
____________________
| index | sub item|
|_______|__________|
| | A | B |
|_______|____|_____|
| 0 | 1 | 2 |
| 1 | 1 | 2 |
| 2 | 1 | 2 |
|_______|____|_____|