-
Notifications
You must be signed in to change notification settings - Fork 9
/
example05-editing.html
84 lines (70 loc) · 2.59 KB
/
example05-editing.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
---
title: Editing
demonstrates:
- adding basic keyboard navigation and editing
- custom editors and validators
- auto-edit settings
controls:
- '<button onclick="grid.setOptions({autoEdit:true})">Auto-edit ON</button>'
- '<button onclick="grid.setOptions({autoEdit:false})">Auto-edit OFF</button>'
requires_scripts:
- dist/compat/slick.editors.js
- dist/compat/slick.formatters.js
requires_slick_scripts:
- plugins/slick.cellrangedecorator.js
- plugins/slick.cellrangeselector.js
- plugins/slick.cellselectionmodel.js
---
<div id="myGrid"></div>
<script>
function requiredFieldValidator(value) {
if (value == null || value == undefined || !value.length) {
return { valid: false, msg: "This is a required field" };
} else {
return { valid: true, msg: null };
}
}
const columns = [
{ field: "title", width: 100, cssClass: "cell-title", editor: Slick.Editors.Text, validator: requiredFieldValidator },
{ field: "description", width: 120, editor: Slick.Editors.LongText },
{ field: "duration", editor: Slick.Editors.Text },
{ field: "percentComplete", name: "% Complete", width: 80, resizable: false, format: Slick.PercentCompleteBarFormatter, editor: Slick.PercentCompleteEditor },
{ field: "start", minWidth: 110, editor: Slick.Editors.Date },
{ field: "finish", minWidth: 110, editor: Slick.Editors.Date },
{ field: "effortDriven", width: 80, minWidth: 20, maxWidth: 80, cssClass: "cell-effort-driven", editor: Slick.CheckboxEditor, format: Slick.CheckboxFormatter }
];
const data = [];
for (var i = 0; i < 500; i++) {
var d = (data[i] = {});
d["title"] = "Task " + i;
d["description"] = "This is a sample task description.\n It can be multiline";
d["duration"] = "5 days";
d["percentComplete"] = Math.round(Math.random() * 100);
d["start"] = "01/01/2009";
d["finish"] = "01/05/2009";
d["effortDriven"] = (i % 5 == 0);
}
const grid = new Slick.Grid("#myGrid", data, columns, {
editable: true,
enableAddRow: true,
enableCellNavigation: true,
asyncEditorLoading: false,
autoEdit: false
});
grid.setSelectionModel(new Slick.CellSelectionModel());
grid.onAddNewRow.subscribe(function (e, args) {
var item = args.item;
grid.invalidateRow(data.length);
data.push(item);
grid.updateRowCount();
grid.render();
});
</script>
<style>
.cell-title {
font-weight: bold;
}
.cell-effort-driven {
text-align: center;
}
</style>