-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathexample-0031-row-span-employees.html
More file actions
373 lines (350 loc) · 16.6 KB
/
Copy pathexample-0031-row-span-employees.html
File metadata and controls
373 lines (350 loc) · 16.6 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link rel="shortcut icon" type="image/ico" href="favicon.ico" />
<title>SlickGrid Example: Basic Grid: Showing rowspan</title>
<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"/>
<link rel="stylesheet" href="../dist/styles/css/slick-icons.css" type="text/css"/>
<style>
#myGrid {
--alpine-odd-row-color: #fff;
--alpine-cell-border-width: 0 1px 1px 0;
--alpine-row-mouse-hover-color: transparent;
}
#myGrid .slick-cell.rowspan {
z-index: 9;
}
#myGrid .slick-cell {
display: flex;
align-items: center;
/* justify-content: center; */
}
</style>
</head>
<body>
<h2 class="title">Example colspan/rowspan - Employees Timesheets</h2>
<div>
<h2>
<a href="/examples/index.html" style="text-decoration: none; font-size: 22px">⌂</a>
Demonstrates:
</h2>
<p>
This sample demonstrates the Grid component with the row spanning feature.
In this sample, you will see multiple columns and rows spanning.
</p>
<div>
<b>NOTE</b>: "rowspan" is an opt-in feature, because of its small perf hit (it needs to loop through all row metadatas to map all rowspan), and requires the <code>enableCellRowSpan</code> grid option to be enabled to work properly.
</div>
<div>
<b>NOTE 2</b>: <code>colspan</code>/<code>rowspan</code> are both using DataView item metadata and are both based on row indexes and will <b>not</b>
update neither keep the row in sync with the data. It is really up to you the user to update the metadata logic of how and where the cells should span.
(i.e: Filtering/Sorting/Paging/... will <b>not</b> change/update the spanning in the grid by itself)
</div>
<div>
<b>NOTE 3</b>: column/row freezing (pinning) are <b>not supported</b>, or at least not recommended unless you know exactly what you're doing!
Any freezing column/row that could intersect because of a colspan/rowspan <b>will cause problems</b>.
</div>
<h2>
View Source:
<a href="https://github.com/6pac/SlickGrid/blob/master/examples/example-0031-row-span-employees.html" target="_sourcewindow">
View the source for this example on Github
</a>
</h2>
<div style="display: inline-flex; gap: 5px">
<button class="btn" data-test="goto-up" onclick="grid.navigateUp()" title="from an active cell, navigate to cell above">
<span class="sgi sgi-chevron-left rotate-90"> </span>Navigate Up Cell
</button>
<button class="btn" data-test="goto-down" onclick="grid.navigateDown()" title="from an active cell, navigate to cell below">
<span class="sgi sgi-chevron-left rotate-270"> </span>Navigate Down Cell
</button>
<button class="btn" data-test="goto-prev" onclick="grid.navigatePrev()" title="from an active cell, navigate to previous left cell">
<span class="sgi sgi-chevron-left"></span> Navigate to Left Cell
</button>
<button class="btn" data-test="goto-next" onclick="grid.navigateNext()" title="from an active cell, navigate to next right cell">
<span class="sgi sgi-chevron-left rotate-180"> </span>Navigate to Right Cell
</button>
<button class="btn" data-test="toggle-employee-id" onclick="toggleEmployeeIdVisibility()">
Show/Hide EmployeeID
</button>
<button class="btn" style="margin-left: 10px" data-test="toggle-editing" onclick="toggleEditing()" title="from an active cell, navigate to next right cell">
<span class="sgi sgi-pencil-outline"> </span>
Toggle Editing: <span id="isEditable" class="text-italic">false</span>
</button>
</div>
</div>
<br>
<div>
<div style="position:relative">
<div style="width: calc(100vw - 30px);">
<div class="grid-header" style="width:100%;top:400px">
<label>SlickGrid - Employees Timesheets</label>
</div>
<div id="myGrid" class="slick-container" style="width:100%;height:350px;"></div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></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.formatters.js"></script>
<script src="../dist/browser/slick.editors.js"></script>
<script src="../dist/browser/plugins/slick.cellrangedecorator.js"></script>
<script src="../dist/browser/plugins/slick.cellrangeselector.js"></script>
<script src="../dist/browser/plugins/slick.cellexternalcopymanager.js"></script>
<script src="../dist/browser/plugins/slick.cellselectionmodel.js"></script>
<script src="../dist/browser/slick.dataview.js"></script>
<script>
// this example replicates this SyncFusion grid demo: https://ej2.syncfusion.com/demos/#/bootstrap5/grid/row-spanning.html
let grid;
let columns = [
{ id: "employeeID", name: "Employee ID", field: "employeeID", width: 100 },
{ id: "employeeName", name: "Employee Name", field: "employeeName", editor: Slick.Editors.Text, width: 120 },
{ id: "9:00", name: "9:00 AM", field: "9:00", editor: Slick.Editors.Text, width: 120 },
{ id: "9:30", name: "9:30 AM", field: "9:30", editor: Slick.Editors.Text, width: 120 },
{ id: "10:00", name: "10:00 AM", field: "10:00", editor: Slick.Editors.Text, width: 120 },
{ id: "10:30", name: "10:30 AM", field: "10:30", editor: Slick.Editors.Text, width: 120 },
{ id: "11:00", name: "11:00 AM", field: "11:00", editor: Slick.Editors.Text, width: 120 },
{ id: "11:30", name: "11:30 AM", field: "11:30", editor: Slick.Editors.Text, width: 120 },
{ id: "12:00", name: "12:00 PM", field: "12:00", editor: Slick.Editors.Text, width: 120 },
{ id: "12:30", name: "12:30 PM", field: "12:30", editor: Slick.Editors.Text, width: 120 },
{ id: "1:00", name: "1:00 PM", field: "1:00", editor: Slick.Editors.Text, width: 120 },
{ id: "1:30", name: "1:30 PM", field: "1:30", editor: Slick.Editors.Text, width: 120 },
{ id: "2:00", name: "2:00 PM", field: "2:00", editor: Slick.Editors.Text, width: 120 },
{ id: "2:30", name: "2:30 PM", field: "2:30", editor: Slick.Editors.Text, width: 120 },
{ id: "3:00", name: "3:00 PM", field: "3:00", editor: Slick.Editors.Text, width: 120 },
{ id: "3:30", name: "3:30 PM", field: "3:30", editor: Slick.Editors.Text, width: 120 },
{ id: "4:00", name: "4:00 PM", field: "4:00", editor: Slick.Editors.Text, width: 120 },
{ id: "4:30", name: "4:30 PM", field: "4:30", editor: Slick.Editors.Text, width: 120 },
{ id: "5:00", name: "5:00 PM", field: "5:00", editor: Slick.Editors.Text, width: 120 },
];
let metadata = {
// 10001: Davolio
0: {
columns: {
1: { rowspan: 2 },
2: { colspan: 2 },
6: { colspan: 3 },
10: { colspan: 3, rowspan: 10 },
13: { colspan: 2 },
17: { colspan: 2, rowspan: 2 }
}
},
// 10002: (Buchanan... name not shown since Davolio has rowspan=2)
1: {
columns: {
3: { colspan: 3 },
6: { colspan: 4 },
13: { colspan: 2, rowspan: 5 },
15: { colspan: 2 },
}
},
// 10003: Fuller
2: {
columns: {
2: { colspan: 3, rowspan: 2 },
5: { colspan: 2 },
7: { colspan: 3 },
15: { colspan: 2 },
17: { colspan: 2 },
}
},
// 10004: Leverling
3: {
columns: {
6: { colspan: 4 },
16: { colspan: 2 },
}
},
// 10005: Peacock
4: {
columns: {
2: { colspan: 4 },
7: { colspan: 3 },
15: { colspan: 2, rowspan: 2 },
17: { colspan: 2 },
}
},
// 10006: Janet
5: {
columns: {
2: { colspan: 2 },
4: { colspan: 3 },
7: { colspan: 3 },
17: { colspan: 2 },
}
},
// 10007: Suyama
6: {
columns: {
2: { colspan: 2 },
5: { colspan: 2 },
7: { colspan: 3 },
14: { colspan: 2 },
16: { colspan: 3 },
}
},
// 10008: Robert
7: {
columns: {
2: { colspan: 3 },
5: { colspan: 3 },
13: { colspan: 3, rowspan: 2 },
16: { colspan: 2 }
}
},
// 10009: Andrew
8: {
columns: {
2: { colspan: 3 },
7: { colspan: 3, rowspan: 2 },
17: { colspan: 2 }
}
},
// 10010: Michael
9: {
columns: {
2: { colspan: 3 },
5: { colspan: 2 },
13: { colspan: 3 },
16: { colspan: 3 },
}
},
};
let options = {
editable: false,
enableCellNavigation: true,
enableColumnReorder: false,
enableCellRowSpan: true, // required flag for rowspan
frozenColumn: 0,
rowHeight: 30,
rowTopOffsetRenderType: 'top' // rowspan doesn't render well with 'transform', default is 'top'
};
let showEmployeeId = true;
function toggleEditing() {
const isEditable = !grid.getOptions().editable;
grid.setOptions({ editable: isEditable });
document.querySelector('#isEditable').textContent = isEditable;
}
// when a side effect happens (e.g. show/hide EmployeeID),
// you have to recalculate the metadata by yourself
// if column index(es) aren't changing then "invalidateRows()" or "invalidate()" might be sufficient
// however, when column index(es) changed then you will have to call "remapAllColumnsRowSpan()" to clear & reevaluate the rowspan cache
function toggleEmployeeIdVisibility() {
const newMetadata = {};
showEmployeeId = !showEmployeeId;
// direction to calculate new column indexes (-1 or +1 on the column index)
// e.g. metadata = `{0:{columns:{1:{rowspan: 2}}}}` if we hide then new result is `{0:{columns:{0:{rowspan: 2}}}}`
const dir = showEmployeeId ? 1 : -1;
for (let row of Object.keys(metadata)) {
newMetadata[row] = { columns: {} };
for (let col of Object.keys(metadata[row].columns)) {
newMetadata[row].columns[Number(col) + dir] = metadata[row].columns[col];
}
}
// update column definitions
if (showEmployeeId) {
columns.unshift({ id: "employeeID", name: "Employee ID", field: "employeeID", width: 100 });
} else {
columns.splice(0, 1);
}
grid.setColumns(columns);
// update & remap rowspans
metadata = newMetadata;
grid.remapAllColumnsRowSpan();
grid.invalidate();
}
document.addEventListener("DOMContentLoaded", () => {
let data = [];
// Option #1
// dataView.getItemMetadata = (row) => {
// return metadata[row];
// };
// Option #2
const dataView = new Slick.Data.DataView({
globalItemMetadataProvider: {
getRowMetadata: (item, row) => {
return metadata[row];
}
}
});
grid = new Slick.Grid("#myGrid", dataView, columns, options);
grid.setSelectionModel(new Slick.CellSelectionModel());
grid.registerPlugin(new Slick.CellExternalCopyManager());
dataView.onRowCountChanged.subscribe((e, args) => {
grid.updateRowCount();
grid.render();
});
dataView.onRowsChanged.subscribe((e, args) => {
grid.invalidateRows(args.rows);
grid.render();
});
grid.onBeforeEditCell.subscribe((e, args) => {
if (args.column.field === 'employeeID' || args.column.field === '1:00') {
return false;
}
});
grid.init();
dataView.beginUpdate();
dataView.setItems(getData(), 'employeeID');
dataView.endUpdate();
});
function getData() {
return [
{
employeeID: 10001, employeeName: 'Davolio', '9:00': 'Analysis Tasks', '9:30': 'Analysis Tasks', '10:00': 'Team Meeting', '10:30': 'Testing',
'11:00': 'Development', '11:30': 'Development', '12:00': 'Development', '12:30': 'Support', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Testing', '3:00': 'Testing', '3:30': 'Development', '4:00': 'Conference', '4:30': 'Team Meeting', '5:00': 'Team Meeting'
},
{
employeeID: 10002, employeeName: 'Buchanan', '9:00': 'Task Assign', '9:30': 'Support', '10:00': 'Support', '10:30': 'Support',
'11:00': 'Testing', '11:30': 'Testing', '12:00': 'Testing', '12:30': 'Testing', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Development', '3:00': 'Development', '3:30': 'Check Mail', '4:00': 'Check Mail', '4:30': 'Team Meeting', '5:00': 'Team Meeting'
},
{
employeeID: 10003, employeeName: 'Fuller', '9:00': 'Check Mail', '9:30': 'Check Mail', '10:00': 'Check Mail', '10:30': 'Analysis Tasks',
'11:00': 'Analysis Tasks', '11:30': 'Support', '12:00': 'Support', '12:30': 'Support', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Development', '3:00': 'Development', '3:30': 'Team Meeting', '4:00': 'Team Meeting', '4:30': 'Development', '5:00': 'Development'
},
{
employeeID: 10004, employeeName: 'Leverling', '9:00': 'Testing', '9:30': 'Check Mail', '10:00': 'Check Mail', '10:30': 'Support',
'11:00': 'Testing', '11:30': 'Testing', '12:00': 'Testing', '12:30': 'Testing', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Development', '3:00': 'Development', '3:30': 'Check Mail', '4:00': 'Conference', '4:30': 'Conference', '5:00': 'Team Meeting'
},
{
employeeID: 10005, employeeName: 'Peacock', '9:00': 'Task Assign', '9:30': 'Task Assign', '10:00': 'Task Assign', '10:30': 'Task Assign',
'11:00': 'Check Mail', '11:30': 'Support', '12:00': 'Support', '12:30': 'Support', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Development', '3:00': 'Development', '3:30': 'Team Meeting', '4:00': 'Team Meeting', '4:30': 'Testing', '5:00': 'Testing'
},
{
employeeID: 10006, employeeName: 'Janet', '9:00': 'Testing', '9:30': 'Testing', '10:00': 'Support', '10:30': 'Support',
'11:00': 'Support', '11:30': 'Team Meeting', '12:00': 'Team Meeting', '12:30': 'Team Meeting', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Development', '3:00': 'Development', '3:30': 'Team Meeting', '4:00': 'Team Meeting', '4:30': 'Development', '5:00': 'Development'
},
{
employeeID: 10007, employeeName: 'Suyama', '9:00': 'Analysis Tasks', '9:30': 'Analysis Tasks', '10:00': 'Testing', '10:30': 'Development',
'11:00': 'Development', '11:30': 'Testing', '12:00': 'Testing', '12:30': 'Testing', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Support', '3:00': 'Build', '3:30': 'Build', '4:00': 'Check Mail', '4:30': 'Check Mail', '5:00': 'Check Mail'
},
{
employeeID: 10008, employeeName: 'Robert', '9:00': 'Task Assign', '9:30': 'Task Assign', '10:00': 'Task Assign', '10:30': 'Development',
'11:00': 'Development', '11:30': 'Development', '12:00': 'Testing', '12:30': 'Support', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Check Mail', '3:00': 'Check Mail', '3:30': 'Check Mail', '4:00': 'Team Meeting', '4:30': 'Team Meeting', '5:00': 'Build'
},
{
employeeID: 10009, employeeName: 'Andrew', '9:00': 'Check Mail', '9:30': 'Team Meeting', '10:00': 'Team Meeting', '10:30': 'Support',
'11:00': 'Testing', '11:30': 'Development', '12:00': 'Development', '12:30': 'Development', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Check Mail', '3:00': 'Check Mail', '3:30': 'Check Mail', '4:00': 'Team Meeting', '4:30': 'Development', '5:00': 'Development'
},
{
employeeID: 10010, employeeName: 'Michael', '9:00': 'Task Assign', '9:30': 'Task Assign', '10:00': 'Task Assign', '10:30': 'Analysis Tasks',
'11:00': 'Analysis Tasks', '11:30': 'Development', '12:00': 'Development', '12:30': 'Development', '1:00': 'Lunch Break', '1:30': 'Lunch Break',
'2:00': 'Lunch Break', '2:30': 'Testing', '3:00': 'Testing', '3:30': 'Testing', '4:00': 'Build', '4:30': 'Build', '5:00': 'Build'
}
];
}
</script>
</body>
</html>