forked from lawrencepit/slick-grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid.html
360 lines (291 loc) · 11.3 KB
/
grid.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
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Spreadsheet prototype</title>
<link rel="stylesheet" href="simpledropdown.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="slick.grid.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="themes/smoothness/ui.all.css" type="text/css" media="screen" charset="utf-8" />
<style>
*
{
font-family: arial;
font-size: 8pt;
}
hr {
height: 1px;
border: 0;
background: silver;
}
#grid {
background: white;
outline: 0px;
}
ul {
padding: 0px;
cursor: default;
}
li {
background: url("images/arrow_right_spearmint.png") no-repeat 0px center;
padding-left: 12px;
list-style: none;
margin: 0px;
}
li:hover {
background: url("images/arrow_right_peppermint.png") no-repeat 0px center;
}
.listview-header {
height: 24px;
line-height: 24px;
width: 100%;
background: url("images/listview.gif") no-repeat top left;
}
.listview-header .r {
float:right;
text-align: right;
width: 50%;
height: 24px;
background: white url("images/listview.gif") no-repeat top right;
line-height: 24px;
}
.listview-header input {
border: 1px solid silver;
}
.listview-footer {
height: 24px;
line-height: 24px;
width: 100%;
background: url("images/listview.gif") no-repeat left -24px;
}
.listview-footer .r {
float:right;
text-align: right;
width: 50%;
height: 24px;
background: white url("images/listview.gif") no-repeat right -24px;
line-height: 24px;
}
</style>
</head>
<body>
<script language="JavaScript" src="lib/firebugx.js"></script>
<script language="JavaScript" src="lib/jquery-1.3.2.min.js"></script>
<script language="JavaScript" src="lib/jquery-ui-1.7.custom.min.js"></script>
<script language="JavaScript" src="lib/jquery.getScrollbarWidth.js"></script>
<script language="JavaScript" src="lib/jquery.rule-1.0.1-min.js"></script>
<script language="JavaScript" src="slick.editors.js"></script>
<script language="JavaScript" src="slick.grid.js"></script>
<script language="JavaScript" src="slick.globaleditorlock.js"></script>
<div class="listview-header">
<div style="float:left;padding-left:14px;">
<span class="simple-dropdown">
<em>Reload grid</em>
<div>
<a href="javascript:reinitGrid(10)">Load 10 rows</a>
<a href="javascript:reinitGrid(100)">Load 100 rows</a>
<a href="javascript:reinitGrid(500)">Load 500 rows</a>
<a href="javascript:reinitGrid(1000)">Load 1'000 rows</a>
<a href="javascript:reinitGrid(5000)">Load 5'000 rows</a>
<a href="javascript:reinitGrid(50000)">Load 50'000 rows</a>
</div>
</span>
<span class="simple-dropdown">
<em>Change column styles</em>
<div>
<a href="javascript:updateModel('%', {formatter:PercentCompleteCellFormatter, cssClass:'task-percent'})">Render <b>% Complete</b> as text</a>
<a href="javascript:updateModel('%', {formatter:GraphicalPercentCompleteCellFormatter, cssClass:null})">Render <b>% Complete</b> as graph</a>
</div>
</span>
<span class="simple-dropdown">
<em>Select rows</em>
<div>
<a href="javascript:grid.setSelectedRows([0,1,2,3,4])">0 - 5</a>
</div>
</span>
<span class="simple-dropdown">
<em>Options</em>
<div>
<a href="javascript:grid.setOptions({enableAddRow:true})">enableAddRow = true</a>
<a href="javascript:grid.setOptions({enableAddRow:false})">enableAddRow = false</a>
<hr/>
<a href="javascript:grid.setOptions({editable:true})">editable = true</a>
<a href="javascript:grid.setOptions({editable:false})">editable = false</a>
<hr/>
<a href="javascript:grid.setOptions({editOnDoubleClick:true})">editOnDoubleClick = true</a>
<a href="javascript:grid.setOptions({editOnDoubleClick:false})">editOnDoubleClick = false</a>
<hr/>
<a href="javascript:grid.setOptions({enableCellNavigation:true})">enableCellNavigation = true</a>
<a href="javascript:grid.setOptions({enableCellNavigation:false})">enableCellNavigation = false</a>
<hr/>
<a href="javascript:grid.setOptions({asyncEditorLoading:true})">asyncEditorLoading = true</a>
<a href="javascript:grid.setOptions({asyncEditorLoading:false})">asyncEditorLoading = false</a>
</div>
</span>
<span class="simple-dropdown">
<em>Debug</em>
<div>
<a href="javascript:grid.benchmarkFn('removeAllRows')">benchmark removeAllRows</a>
<a href="javascript:grid.benchmarkFn('render')">benchmark render</a>
<a href="javascript:grid.benchmarkFn('benchmark_render_200')">benchmark render 200</a>
<hr/>
<a href="javascript:grid.stressTest()">stress test (infinite render/clear cycle)</a>
<hr/>
<a href="javascript:grid.debug()">internal state</a>
</div>
</span>
<span class="simple-dropdown">
<em style="padding-left:16px;background:url('images/info.gif') no-repeat center left;">Quick info</em>
<div style="max-width:600px">
This page demonstrate the use of a SlickGrid control.
<br><br>
<b>Key features:</b>
<ul>
<li>Virtual rendering/scrolling (hundreds of thousands of rows)</li>
<li>Extremely fast rendering speed</li>
<li>Support for a Model data source</li>
<li>Support for Ajax-loaded data</li>
<li>Multiple row selection</li>
<li>Edit and add new rows</li>
<li>Keyboard navigation for cell selection</li>
<li>Custom renderers for cells with conditional formatting</li>
<li>Formatters adaptive to column width</li>
<li>Custom editors for cells</li>
<li>Resizable and reorderable columns</li>
<li>Highly customizable & configurable</li>
<li>Built-in validators</li>
<li>Callbacks for events</li>
<li>Much much more...</li>
</ul>
</div>
</span>
</div>
<div class="r">
<div style="padding-right:14px;">
<label>Filter:</label> <input type=text>
</div>
</div>
</div>
<div id="myGrid" style="width:100%;height:500px;"></div>
<div class="listview-footer">
<div style="float:left;padding-left:14px;">
</div>
<div class="r">
<div style="padding-right:14px;">
</div>
</div>
</div>
<br/>
<script>
$(".simple-dropdown a").click(function(e) {
var dd = $(this).closest(".simple-dropdown > div");
dd.css("display", "none");
window.setTimeout(function () { dd.css("display", ""); }, 10);
});
function nonEmptyValidator(value) {
if (value == null || value == undefined || !value.length)
return {valid:false, msg:"This is a required field"};
else
return {valid:true, msg:null};
}
function setTaskResources(resourcesNamesArray, cellInfo, dataContext)
{
dataContext["resources"] = resourcesNamesArray.length > 0 ? resourcesNamesArray.concat() : null;
}
var data = [];
var grid;
var model = [
{id:"#", name:"#", cssClass:"cell-move-handle", width:60, resizable:false, unselectable:true, formatter:SelectorCellFormatter},
{id:"title", name:"Title", field:"title", formatter:TaskNameFormatter, width:300, editor:TextCellEditor, validator:nonEmptyValidator},
{id:"star", name:"<img src='images/bullet_star.png' align='absmiddle'>", field:"starred", formatter:StarFormatter, editor:StarCellEditor, width:16, resizable:false, cannotTriggerInsert:true},
{id:"duration", name:"Duration", field:"duration", width:80, editor:TextCellEditor},
{id:"%", name:"% Complete", field:"percentComplete", formatter:GraphicalPercentCompleteCellFormatter, width:60, editor:PercentCompleteCellEditor},
{id:"start", name:"Start", field:"start", width:100, editor:DateCellEditor},
{id:"finish", name:"Finish", field:"finish", width:100, editor:DateCellEditor},
{id:"resources", name:"Resources", formatter:ResourcesFormatter, rerenderOnResize:true, width:200, editor:ResourcesCellEditor, setValueHandler:setTaskResources, cannotTriggerInsert:true, minWidth:16, maxWidth:200},
{id:"preds", name:"Predecessors", width:100, editor:TextCellEditor, cannotTriggerInsert:true}
,
{id:"e", name:"Deliverable", field:4, formatter:YesNoCellFormatter, width:60, editor:YesNoSelectCellEditor, cannotTriggerInsert:true},
{id:"f", name:"Effort-driven", field:5, formatter:YesNoCellFormatter, width:50, editor:YesNoCheckboxCellEditor, cannotTriggerInsert:true}
];
function updateModel(id, args) {
if (GlobalEditorLock.isEditing() && !GlobalEditorLock.commitCurrentEdit()) return;
for (var i=0; i<model.length; i++)
{
if (model[i].id == id) {
model[i] = $.extend(model[i], args);
grid.removeAllRows();
grid.render();
return;
}
}
}
$(function()
{
$("#myGrid")[0].unselectable = true;
reinitGrid(10);
})
function enterEdit() {
GlobalEditorLock.enterEditMode({
commitCurrentEdit: function() { alert('validation error'); return false },
cancelCurrentEdit: function() {}
});
}
function doSomething() {
if (GlobalEditorLock.isEditing() && !GlobalEditorLock.commitCurrentEdit()) return;
/*
if (GlobalEditorLock.isEditing())
{
if (confirm("Cancel current edit?"))
GlobalEditorLock.cancelCurrentEdit();
else
return;
}
*/
alert("Editor lock acquired")
}
function reinitGrid(loadedRows,totalRows) {
data = [];
for (var i = 0; i < loadedRows; i++)
{
var d = (data[i] = {});
d["title"] = "Task " + i;
d["duration"] = "5 days";
d["percentComplete"] = Math.round(Math.random() * 100);
d["start"] = "01/01/2009";
d["finish"] = "01/05/2009";
d["indent"] = i % 5;
d["resources"] = (i % 7 == 0) ? ["Boris The Blade", "Bullet Tooth"] : (i % 11 == 0 ? ["Bricktop"] : null);
}
if (grid) grid.destroy();
grid = new SlickGrid($("#myGrid"), data, model, {});
grid.onValidationError = function(elem, validationResults, row, cell, cellInfo) {
console.warn(validationResults.msg);
}
grid.onAddNewRow = function(cellInfo, value) {
var item = {title:"New task", indent:0, duration:"1 day", percentComplete:0, start:"01/01/2009", finish:"01/01/2009"};
item[cellInfo.field] = value;
data[data.length] = item;
grid.resizeCanvas();
grid.render();
grid.updateRow(data.length-1);
}
grid.onClick = function(e, row, cell) {
// toggle expand/collapse icon
if (model[cell].id == "title" && $(e.target).is("img"))
{
$(e.target).attr("src", $(e.target).attr("src") != "images/collapse.gif" ? "images/collapse.gif" : "images/expand.gif");
return true;
}
if (model[cell].id == "#")
{
grid.setSelectedRows([row]);
}
// pass the event through
return false;
}
}
</script>
<button onclick="doSomething()">Test GlobalEditorLock lock</button>
</body>
</html>