Header Merging

FlexGrid supports content-driven cell merging in column header cells.

Country
Sales
Expenses
Active
US
81,732.54
38,401.13
Germany
20,603.32
27,944.24
UK
44,217.79
48,877.49
Japan
29,190.63
23,365.74
US
46,951.19
49,107.56
Germany
86,237.02
49,767.35
UK
31,459.18
40,845.40
Japan
99,190.22
1,631.26
US
52,628.41
46,700.93
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
// This file locates: "Scripts/Lesson/C1FlexGrid/HeaderMerging.js".
c1.documentReady(function () {
    var theGrid = wijmo.Control.getControl('#theGrid');
    theGrid.allowMerging = 'ColumnHeaders';
 
    // create extra header row
    var extraRow = new wijmo.grid.Row();
    extraRow.allowMerging = true;
 
    // add extra header row to the grid
    var panel = theGrid.columnHeaders;
    panel.rows.splice(0, 0, extraRow);
 
    // populate the extra header row
    for (col = 1; col <= 2; col++) {
        panel.setCellData(0, col, 'Amounts');
    }
 
    // merge "Country" and "Active" headers vertically
    ['Country', 'Active'].forEach(function (binding) {
        col = theGrid.getColumn(binding);
        col.allowMerging = true;
        panel.setCellData(0, col.index, col.header);
    });
 
    // center-align merged header cells
    theGrid.formatItem.addHandler(function (s, e) {
        if (e.panel == s.columnHeaders && e.range.rowSpan > 1) {
            var html = e.cell.innerHTML;
            e.cell.innerHTML = '<div class="v-center">' + html + '</div>';
        }
    });
});
1
2
3
4
5
6
7
// This file locates: "Content/css/Lesson/C1FlexGrid/HeaderMerging.css".
.wj-cell .v-center {
  position: relative;
  top: 50%;
    transform: translateY(-50%);
  white-space: pre-wrap;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1FlexGridController : Controller
    {
        // GET: HeaderMerging
        public ActionResult HeaderMerging()
        {
            return View(Models.FlexGridData.GetSales(Models.FlexGridData.Countries4, 20));
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@model IEnumerable<FlexGridData.Sale>
 
<h1>
    @Html.Raw(Resources.C1FlexGrid.HeaderMerging_Title)
</h1>
<p>
    @Html.Raw(Resources.C1FlexGrid.HeaderMerging_Text1)
</p>
 
@(Html.C1().FlexGrid().Id("theGrid").Height(200)
    .ShowAlternatingRows(false)
    .Bind(Model)
    .AutoGenerateColumns(false)
    .Columns(cs=>
    {
        cs.Add().Binding("Country").Header("Country");
        cs.Add().Binding("Sales").Header("Sales").Format("n2");
        cs.Add().Binding("Expenses").Header("Expenses").Format("n2");
        cs.Add().Binding("Active").Header("Active");
    })
)