forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.html
More file actions
212 lines (199 loc) · 6.74 KB
/
grid.html
File metadata and controls
212 lines (199 loc) · 6.74 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid: Editing, Inline Grid</title>
<link rel="stylesheet" href="../themes/base/jquery.ui.all.css">
<link rel="stylesheet" href="../demos/demos.css">
<script src="../jquery-1.7.2.js"></script>
<script src="../external/globalize.js"></script>
<script src="../external/globalize.culture.de-DE.js"></script>
<script src="../external/jquery.tmpl.js"></script>
<script src="../external/jquery.mousewheel.js"></script>
<script src="../ui/jquery.ui.core.js"></script>
<script src="../ui/jquery.ui.widget.js"></script>
<script src="../ui/jquery.ui.button.js"></script>
<script src="../ui/jquery.ui.spinner.js"></script>
<script src="../ui/jquery.ui.position.js"></script>
<script src="../ui/jquery.ui.tooltip.js"></script>
<script src="../ui/jquery.ui.autocomplete.js"></script>
<script src="../ui/jquery.ui.menu.js"></script>
<script src="../ui/jquery.ui.dataview.js"></script>
<script src="../ui/jquery.ui.grid.js"></script>
<script src="../ui/jquery.ui.observable.js"></script>
<script src="../ui/jquery.ui.dataviewlocal.js"></script>
<script src="../grid-spf/pager.js"></script>
<script src="editor.js"></script>
<script src="grid-editor.js"></script>
<script src="editor-countrycomplete.js"></script>
<script src="editor-randomspinner.js"></script>
<script src="navigator.js"></script>
<script src="localstore.js"></script>
<script src="helpers.js"></script>
<script>
if ( !window.console ) {
window.console = {
log: function() {
var message = Array.prototype.slice.call( arguments, 1 ).join( ", " );
$("<div>").text( message ).appendTo("body");
}
}
}
// TODO this breaks the date/time formatting
// need to figure out how to deal with that properly
// put metadata on columns, e.g. for date data-type="date" data-format="d"?
//Globalize.culture( "de-DE" );
var store = $.demos.localstore( {
key: "grid-editing-developers",
initial: "../grid-spf/developers.json"
});
var localDevelopers = store.load();
$(function() {
var developers = $.ui.dataviewlocal({
input: localDevelopers,
paging: {
limit: 8
}
});
var grid = $( "#developers-local" ).grid({
heightStyle: "fill",
source: developers.result
});
grid.gridEditor({
items: "td:not(:has(button))"
});
grid.navigator();
var developer;
var editForm = $( "#editForm" ).tooltip().hide().submit( function( event ) {
event.preventDefault();
$.observable( developer ).property( serializeForm( this ) );
editForm.hide();
grid.focus();
});
grid.delegate( "button.edit", "click", function() {
developer = $( this ).closest("tr").data( "grid-item" );
$( "#edit-tmpl" ).tmpl( meta(developer) ).appendTo( editForm.find("fieldset").empty() );
editForm.show().find("input:first").focus();
});
grid.delegate( "button.remove", "click", function() {
var developer = $( this ).closest("tr").data( "grid-item" );
$.observable( localDevelopers ).remove( developer );
});
$( "#pageDevelopers" ).pager({
source: developers
});
function newDeveloper() {
return {
firstName: [ "Peter", "Unknown", "Carl" ][ Math.floor( Math.random() * 3 ) ],
lastName: [ "Pan", "Unkown", "Worth" ][ Math.floor( Math.random() * 3 ) ],
country: [ "Unknown", "Pandistan", "Petertan" ][ Math.floor( Math.random() * 3 ) ],
bitcoins: Math.floor( Math.random() * 1500 ),
random: {
value: Math.floor( Math.random() * 13 )
},
date: +new Date()
}
}
$( "#addDeveloper" ).click( function() {
$.observable( localDevelopers ).insert( 0, newDeveloper() );
});
$( "#addDeveloperAtEnd" ).click( function() {
$.observable( localDevelopers ).insert( newDeveloper() );
});
developers.refresh();
});
</script>
<style>
.ui-grid tr .navigator-active { background: rgba(0,0,255,0.1); }
.ui-grid input { border: none; margin: 0; }
.ui-autocomplete { width: 200px; max-height: 200px; overflow: auto; }
thead td { text-align: center; }
#pageDevelopers { text-align: center; }
.totals { padding-left: 1em; }
</style>
</head>
<body>
<h1>Grids with editable local dataview</h1>
<h2>local data source</h2>
<p>See also <a href="grid-selectable.html">grid-selectable</a></p>
<div style="width:80em;">
<table id="developers-local">
<caption>Developers Grid</caption>
<colgroup>
<col width="12%">
<col width="12%">
<col width="12%">
<col width="10.34483%">
<col width="12%">
<col width="13.79310%">
<col width="10.34483%">
<col width="6.896552%">
<col width="10.34483%">
</colgroup>
<thead>
<tr>
<th data-property="firstName">First Name</th>
<th data-property="lastName">Last Name</th>
<th data-property="country" data-editor="countrycomplete">Country</th>
<th data-property="bitcoins" data-type="number" data-editor="spinner">Bitcoins</th>
<th data-template="#cell-date-tmpl">Date</th>
<th data-template="#cell-time-tmpl">Time</th>
<th data-property="random.value" data-type="number" data-editor="randomSpinner" data-editor-options='{"min":-1, "max": 125}'>Random</th>
<th data-template="#cell-edit-tmpl">Edit</th>
<th data-template="#cell-remove-tmpl">Remove</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td id="pageDevelopers" colspan="9" class="ui-state-default">
<button data-page="first">First</button>
<button data-page="prev">Prev</button>
<span>
Page <input class="current" size="4"/> of <span class="total">0</span>
</span>
<button data-page="next">Next</button>
<button data-page="last">Last</button>
<span class="totals">
Total records <span class="totalRecords">0</span>
</span>
</td>
</tr>
</tfoot>
</table>
</div>
<div>
<button id="addDeveloper">Insert new developer</button>
<button id="addDeveloperAtEnd">Insert new developer at the end</button>
</div>
<form id="editForm">
<fieldset>
</fieldset>
<input type="submit" value="Save changes" />
</form>
<script id="edit-tmpl" type="text/x-jquery-tmpl">
{{if $.isArray(value)}}
<ul>
{{each(index, valueX) value}}
<li><input type="text" name="${name}" placeholder="${label}" value="${valueX}" title="${label}" /></li>
{{/each}}
</ul>
{{else}}
<input type="text" name="${name}" placeholder="${label}" value="${value}" title="${label}" />
{{/if}}
</script>
<script id="cell-date-tmpl" type="text/x-jquery-tmpl">
<td class="ui-widget-content">${Globalize.format(new Date(date), "d")}</td>
</script>
<script id="cell-time-tmpl" type="text/x-jquery-tmpl">
<td class="ui-widget-content">${Globalize.format(new Date(date), "T")}</td>
</script>
<script id="cell-edit-tmpl" type="text/x-jquery-tmpl">
<td class="ui-widget-content"><button class='edit'>Edit</button></td>
</script>
<script id="cell-remove-tmpl" type="text/x-jquery-tmpl">
<td class="ui-widget-content"><button class='remove'>Remove</button></td>
</script>
</body>
</html>