-
Notifications
You must be signed in to change notification settings - Fork 422
/
example-column-group.html
152 lines (134 loc) · 5.18 KB
/
example-column-group.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" type="image/ico" href="favicon.ico" />
<link rel="stylesheet" href="../dist/styles/css/slick-icons.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/example-demo.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-alpine-theme.css" type="text/css"/>
<style>
.slick-preheader-panel.ui-state-default {
width: 100%;
overflow: hidden;
border-left: 0px !important;
border-bottom: 0px !important;
}
.slick-preheader-panel .slick-header-columns {
border-bottom: 0px !important;
}
</style>
</head>
<body>
<div style="position:relative">
<div style="width:600px;">
<div id="myGrid" class="slick-container" style="width:100%;height:500px;"></div>
</div>
<div class="options-panel">
<h2>
<a href="/examples/index.html" style="text-decoration: none; font-size: 22px">⌂</a>
Demonstrates:
</h2>
<ul>
<li>Extra header row grouping columns into categories</li>
</ul>
<h2>View Source:</h2>
<ul>
<li><A href="https://github.com/6pac/SlickGrid/blob/master/examples/example-column-group.html" target="_sourcewindow"> View the source for this example on Github</a></li>
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/sortablejs/Sortable.min.js"></script>
<script src="sortable-cdn-fallback.js"></script>
<script src="../dist/browser/slick.core.js"></script>
<script src="../dist/browser/slick.interactions.js"></script>
<script src="../dist/browser/slick.grid.js"></script>
<script src="../dist/browser/slick.dataview.js"></script>
<script>
function CreateAddlHeaderRow() {
let preHeaderPanelElm = grid.getPreHeaderPanel();
preHeaderPanelElm.innerHTML = '';
preHeaderPanelElm.className = "slick-header-columns";
preHeaderPanelElm.style.left = '-1000px';
preHeaderPanelElm.style.width = `${grid.getHeadersWidth()}px`;
preHeaderPanelElm.parentElement.classList.add("slick-header");
let headerColumnWidthDiff = grid.getHeaderColumnWidthDiff();
let m, headerElm, lastColumnGroup = '', widthTotal = 0;
const columns = grid.getColumns();
for (let i = 0; i < columns.length; i++) {
m = columns[i];
if (m) {
if (lastColumnGroup === m.columnGroup && i>0) {
widthTotal += m.width;
headerElm.style.width = `${widthTotal - headerColumnWidthDiff}px`;
} else {
widthTotal = m.width;
headerElm = document.createElement('div');
headerElm.className = 'ui-state-default slick-header-column';
headerElm.style.width = `${(m.width || 0) - headerColumnWidthDiff}px`;
headerElm.dataset.group = m.columnGroup || '';
const spanElm = document.createElement('span');
spanElm.className = 'slick-column-name';
spanElm.textContent = m.columnGroup || '';
headerElm.appendChild(spanElm);
preHeaderPanelElm.appendChild(headerElm);
}
lastColumnGroup = m.columnGroup;
}
}
}
let dataView;
let grid;
let data = [];
let options = {
enableCellNavigation: true,
enableColumnReorder: false,
createPreHeaderPanel: true,
showPreHeaderPanel: true,
preHeaderPanelHeight: 23,
explicitInitialization: true
};
let columns = [
{id: "sel", name: "#", field: "num", behavior: "select", cssClass: "cell-selection", width: 40, resizable: false, selectable: false },
{id: "title", name: "Title", field: "title", width: 120, minWidth: 120, cssClass: "cell-title", columnGroup: "Common Factor"},
{id: "duration", name: "Duration", field: "duration", columnGroup: "Common Factor"},
{id: "start", name: "Start", field: "start", minWidth: 60, columnGroup: "Period"},
{id: "finish", name: "Finish", field: "finish", minWidth: 60, columnGroup: "Period"},
{id: "%", defaultSortAsc: false, name: "% Complete", field: "percentComplete", width: 95, resizable: false, columnGroup: "Analysis"},
{id: "effort-driven", name: "Effort Driven", width: 90, minWidth: 20, maxWidth: 90, field: "effortDriven", columnGroup: "Analysis"}
];
for (let i = 0; i < 50000; i++) {
let d = (data[i] = {});
d["id"] = "id_" + i;
d["num"] = i;
d["title"] = "Task " + i;
d["duration"] = "5 days";
d["start"] = "01/01/2009";
d["finish"] = "01/05/2009";
d["percentComplete"] = Math.round(Math.random() * 100);
d["effortDriven"] = (i % 5 == 0);
}
dataView = new Slick.Data.DataView();
grid = new Slick.Grid("#myGrid", dataView, columns, options);
dataView.onRowCountChanged.subscribe(function (e, args) {
grid.updateRowCount();
grid.render();
});
dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
grid.init();
grid.onColumnsResized.subscribe(function (e, args) {
CreateAddlHeaderRow();
});
grid.onColumnsReordered.subscribe(function (e, args) {
CreateAddlHeaderRow();
});
CreateAddlHeaderRow();
// Initialise data
dataView.beginUpdate();
dataView.setItems(data);
dataView.endUpdate();
</script>
</body>
</html>