forked from gnab/editableCell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
209 lines (179 loc) · 9.01 KB
/
index.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
<!-- Either use RequireJS ... -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.min.js"></script>
<!-- .. or include Knockout and editableCell manually -->
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>-->
<!--<script type="text/javascript" src="https://cdn.rawgit.com/gnab/editableCell/v2.1.1/out/editableCell.min.js"></script>-->
<style type="text/css">
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css');
body { padding: 30px; }
dt { font-weight: normal; }
input { padding-left: 8px; }
/* note: these are here if you want to play with the styling;
otherwise, they are unnecessary.
See the README for more information */
.editable-cell-input {
/*outline: 1px solid red;*/
}
.editable-cell-input:hover {
/*outline: 2px solid black;*/
}
.editable-cell-selection {
/*outline: 1px solid green !important;*/
}
.editable-cell-selection:hover {
/*outline: 2px solid yellow !important;*/
}
</style>
</head>
<body>
<p><small><a href="https://github.com/gnab/editableCell" target="_blank">More info</a></small>
<h3>Knockout-EditableCell Demo</h3>
<p class="pull-right"></p>
<h4>Keyboard shortcuts</h4>
<dl class="dl-horizontal">
<dt>
<i class="glyphicon glyphicon-arrow-left"></i>
<i class="glyphicon glyphicon-arrow-right"></i>
<i class="glyphicon glyphicon-arrow-up"></i>
<i class="glyphicon glyphicon-arrow-down"></i>
<kbd>arrows</kbd>
</dt>
<dd>Navigate in the table.</dd>
<dt>
<kbd><kbd>Shift</kbd> + <kbd>arrow</kbd></kbd>
</dt>
<dd>Select cells in the table</dd>
<dt><kbd><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>arrow</kbd></kbd>
</dt>
<dd>Select all cells in the table, starting from currently-selected cell</dd>
<dt><kbd>Escape</kbd></dt>
<dd>Cancel editing</dd>
<dt><kbd>Enter</kbd></dt>
<dd>Complete editing. Your change will also be automatically applied if you navigate away from the cell</dd>
<dt><kbd><kbd>Ctrl</kbd> + <kbd>Enter</kbd></kbd></dt>
<dd>If you have multiple cells selected, and begin editing, this will apply the value to all selected cells</dd>
</dl>
<p>In any editable cell, you can just start typing to edit values. <em>Double-clicking</em> will show the raw value (as in <em>Age</em>, below)</p>
<table style="position: relative" class="table table-bordered table-condensed table-striped table-hover" data-bind="editableCellSelection: selection">
<thead>
<tr>
<th width="30%">Firstname (editable, non-observable)</th>
<th width="30%">Surname (editable)</th>
<th>Salary (read-only)</th>
<th width="20%">Age (editable)</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: entries -->
<tr>
<td data-bind="editableCell: firstName" tabindex="0"></td>
<td data-bind="editableCell: surName" tabindex="0"></td>
<td data-bind="editableCell: 100, cellReadOnly: true" tabindex="0"></td>
<td data-bind="editableCell: age" tabindex="0">
<span data-bind="text: $data"></span> years
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
<p>Combined age: <span data-bind="text: combinedAge"></span></p>
<p>Selection sum: <span data-bind="text: selectionSum"></span></p>
<table style="position: relative" class="table" data-bind="editableCellSelection: selection">
<thead>
<tr>
<th width="30%">Firstname (editable, non-observable)</th>
<th width="30%">Surname (editable)</th>
<th>Salary (read-only)</th>
<th width="20%">Age (editable)</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: entries -->
<tr>
<td data-bind="editableCell: firstName" tabindex="0"></td>
<td data-bind="editableCell: surName" tabindex="0"></td>
<td data-bind="editableCell: 100, cellHTML: salaryFormatted, cellReadOnly: true" tabindex="0"></td>
<td data-bind="editableCell: age" tabindex="0">
<span data-bind="text: $data"></span> years
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
<blockquote>
<p>Because both tables shared the same <code>selection</code>, your selection
will automatically be confined to a single table. In addition, you
can navigate between the two tables using the arrow keys.</p>
</blockquote>
<p>Developers: See the <a href="./docs/knockout.editableCell.html">documented version of the code</a> (created using <a href="http://jashkenas.github.io/docco/">Docco</a>), or <a href="https://github.com/gnab/editableCell/blob/master/index.html" target="_blank">view the source</a> for this page.
</p>
<script type="text/javascript">
requirejs.config({
paths: {
knockout: "https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min",
editableCell: "https://cdn.rawgit.com/gnab/editableCell/v2.1.1/out/editableCell.min"
},
shim: {
editableCell: { deps: ["knockout"] }
}
});
require(['knockout', 'editableCell'], function (ko, ec) {
function ViewModel() {
var self = this;
self.entries = ko.observableArray([
new Person('Bob', 'Geldof', 41),
new Person('Roger', 'Moore', 42),
new Person('James', 'Jameson', 43),
new Person('Andy', 'McLaren', 44),
new Person('Richard', 'Anderson', 45),
]);
self.combinedAge = ko.computed(function () {
var sum = 0;
ko.utils.arrayForEach(self.entries(), function (person) {
sum += parseFloat(person.age());
});
return sum;
});
self.selection = ko.observableArray();
self.selectionSum = ko.computed(function () {
return self.selection()
.filter(function (cell) { return typeof ko.utils.unwrapObservable(cell.value) === 'number'; })
.reduce(function (sum, cell) {
return sum + ko.utils.unwrapObservable(cell.value);
}, 0);
});
}
function Person(firstName, surName, age) {
var self = this;
self._age = ko.observable(age);
self.firstName = firstName;
self.surName = ko.observable(surName);
self.age = ko.computed({
read: this._age,
write: function (newAge) {
var number = parseFloat(newAge);
if (!isNaN(number)) {
self._age(number);
}
}
});
self.props = {
age: ko.observable(10)
};
self.salaryFormatted = ko.computed(function() {
return (self._age() > 30) ?
'<span class="bold">100</span>' :
'<span><i class="glyphicon glyphicon-asterisk"></i> 100</span>';
});
}
var viewModel = new ViewModel(ko);
ko.applyBindings(viewModel);
});
</script>
</body>
</html>