-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.html
189 lines (135 loc) · 6.53 KB
/
example.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
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
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="card">
<div class="card-header">
Basic editable table
</div>
<div class="card-body">
<table id="simpleEditableTable" class="table table-dark table-striped" style="width:100%;">
<thead>
<tr>
<th>Editable cell is beneath</th>
<th>Some column header</th>
<th>Another column header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="editMe">Editable text</td>
<td>Uneditable text</td>
<td>Uneditable text</td>
</tr>
<tr>
<td class="editMe">Editable text</td>
<td>Uneditable text</td>
<td>Uneditable text</td>
</tr>
</tbody>
</table>
</div>
<div class="card-footer bg-transparent border-success">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="basicToggle" checked>
<label class="form-check-label" for="basicToggle">Toggled</label>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="card">
<div class="card-header">
Advanced editable table
</div>
<div class="card-body">
<table id="advancedEditableTable" class="table table-dark table-striped" style="width:100%;">
<thead>
<tr>
<th>Numeric only</th>
<th>Numeric x 100</th>
<th>Custom renderer</th>
</tr>
</thead>
<tbody>
<tr>
<td class="numericEdit">41</td>
<td class="numericTimes100">5</td>
<td class="customRenderer">Pain au chocolat</td>
</tr>
<tr>
<td class="numericEdit">37</td>
<td class="numericTimes100">6</td>
<td class="customRenderer">Pain au chocolat</td>
</tr>
</tbody>
</table>
</div>
<div class="card-footer bg-transparent border-success">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="advancedToggle" checked>
<label class="form-check-label" for="advancedToggle">Toggled</label>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="SimpleTableCellEditor.es6.min.js"></script>
<script>
$(document).ready(function () {
var logAllEvents = true;
//Basic editor with no navigation
var simpleEditor = new SimpleTableCellEditor("simpleEditableTable", {navigation:false});
simpleEditor.SetEditableClass("editMe");
$('#simpleEditableTable').on("cell:edited", function (event) {
console.log(`'${event.oldValue}' changed to '${event.newValue}'`);
});
//Advanced editor
var advancedEditor = new SimpleTableCellEditor("advancedEditableTable");
advancedEditor.SetEditableClass("numericEdit", { validation: $.isNumeric });
advancedEditor.SetEditableClass("numericTimes100", { validation: $.isNumeric, formatter: (val) => { return val * 100; } });
advancedEditor.SetEditableClass("customRenderer", {
internals: {
renderEditor: (elem, oldVal) => {
$(elem).html(`<select>
<option>Pain au chocolat</option>
<option>Chocolatine</option>
</select>`);
$("select option").filter(function () {
return $(this).val() == oldVal;
}).prop('selected', true);
},
extractEditorValue: (elem) => { return $(elem).find('select').val(); },
}
});
//Toggling checkboxes
$("#basicToggle").on('click', function(e){
simpleEditor.Toggle($(e.currentTarget).is(':checked'));
})
$("#advancedToggle").on('click', function(e){
advancedEditor.Toggle($(e.currentTarget).is(':checked'));
})
if (logAllEvents) {
$('table').on("cell:onEditEnter", function (event) {
console.log('onEditEnter event');
});
$('table').on("cell:onEditEntered", function (event) {
console.log('onEditEntered event');
});
$('table').on("cell:onEditExit", function (event) {
console.log('onEditExit event');
});
$('table').on("cell:onEditExited", function (event) {
console.log('onEditExited event');
});
}
});
</script>
</body>
</html>