-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.better.html
253 lines (214 loc) · 5.96 KB
/
jquery.better.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
<!DOCTYPE html>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.better.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<style type="text/css">
.wrapper {
border: 1px solid #ccc;
width: 80%;
padding : 20px;
margin : 10px;
}
#tableToExport {
background-color : #eee;
margin : 0px;
width : 80%;
}
#tableToExport thead tr {
background-color: #cce;
}
#tableToExport th {
padding: 4px 20px;
margin : 0px;
}
#tableToExport td {
padding: 2px 20px;
margin : 0px;
}
.panel {
width:100px;
height:50px;
border : 1px solid black;
}
td.active {
border: 1px dotted #aaa;
background-color: #ccc;
}
/* todo: make the table body scrollable (sub-table in a div) */
#table1 tbody {
height:200px;
overflow-y:scroll;
}
input {
margin-top:5px;
}
tfoot tr {
font-weight : bold;
}
tfoot td {
border-top : 1px solid #ccc;
}
</style>
<script type="text/javascript">
$(function(){
$.better();
$.better.test();
$.better.defaults.downloadUrl = 'bouncefile.php';
// $.better.defaults.downloadMethod = 'console';
$("#downloadTable").click(function(){
$("#tableToExport").better('download', {filename:'table.csv'});
});
$("#downloadText").click(function(){
$.better.download({
data : $("#textarea").text()
, filename : 'text.txt'
, type : 'text/plain'
});
});
$("#wrapper").better('panel', {
stick : 'top right'
, pivot : 'middle right'
// , offset : '0 -25'
}).text('panel1');//.css('background-color', 'green');
$("#tableToExport thead").better('panel', {
stick : 'top right'
, pivot : 'top right'
, offset : '0 0'
, height : 'inherit'
}).text('panel2');//.css('background-color', 'green');
var $s = $("#fieldname").better('panel', {
stick : 'top left'
, pivot : 'top left'
, offset : '0 0'
, height : 'inherit'
, panel : $("<div />", {style: 'width:25px;height:10px;background-color:red;overflow:auto'})
});//.css('background-color', 'green');
$s.text('panel3');
$s.css({width:'auto'});
$.better.plugins.panels.recalc();
});
</script>
<h2>Some header</h2>
<p>some text...</p>
<div class='elements wrapper' id='wrapper'>
<table id='tableToExport'>
<thead>
<tr>
<th id='fieldname'>Name</th>
<th>Age</th>
<th>Qualified</th>
</tr>
</thead>
<tr>
<td>Vasya</td>
<td>18</td>
<td>Yes</td>
</tr>
<tr>
<td>Petya</td>
<td>25</td>
<td>No</td>
</tr>
<tr style='display:none'>
<td>Nastya</td>
<td>39</td>
<td>No</td>
</tr>
</table>
<input type="button" id="downloadTable" value="Download this table as table.csv" />
</div>
<div class='elements wrapper'>
<textarea id='textarea' cols="50" rows="5">
Some
multiline
text
</textarea><br />
<input type="button" id="downloadText" value="Download this text as text.txt" />
</div>
<div class='elements wrapper'>
<label for="managedFilter">Filter `Managed`:</label>
<select id="managedFilter">
<option value="">-none-</option>
<option value="alpha">alpha</option>
<option value="beta">beta</option>
<option value="alpha beta">alpha and beta</option>
</select>
<label for="progressFilter">Display `Progress` greater than:</label>
<input id="progressFilter" type="text" value="0" size="5">
<br />
<input class="button" id="projectFilter" type="button" value="Display `Project 3*`">
<input class="button" id="toggleEditable" type="button" value="Make editable" style="width:150px">
<table id='table1' style='width:80%' class="table table-condensed">
<tr>
<th field="project">Project</th>
<th field="progress">Progress</th>
<th field="status">Status</th>
<th field="managed">Managed</th>
</tr>
</table>
</div>
<script type="text/javascript">
$("#toggleEditable").toggle(function(){
$(this).val("Disable editable");
$("#table1").addClass("editable");
}, function(){
$(this).val("Make editable");
$("#table1").removeClass("editable");
});
$("#managedFilter").on('change', function(){
var val = $(this).val();
if ( ! val)
$("#table1").trigger('filter');
else {
if (val.indexOf(" ") !== -1) val = val.split(" ");
$("#table1").trigger('filter', ["managed", val]);
}
});
$("#progressFilter").on('change', function(){
var val = parseInt($(this).val());
if (isNaN(val))
val = 0;
$(this).val(val);
$("#table1").trigger('filter', ["progress", val, 'gte']);
});
$("#projectFilter").on('click', function(){
$("#table1").trigger('filter', ["project", NaN, function(val, v){return /Project 3\d/.test(v);}]);
});
// populate the table
for (var i=1; i<=50; i+=1) {
$("#table1").append(
$("<tr />").attr("id", i)
.append($("<td />",{text : "Project "+i}))
.append($("<td />",{text : Math.round(Math.random() * 100)}).css('text-align','right'))
.append($("<td />",{text : Math.round(Math.random())}))
.append($("<td />",{text : Math.floor(Math.random() * 5)}))
);
}
$("#table1").attr('submitUrl', "save.php");
// set field attributes
$("#table1").find("th[field='project']").attr({
total : JSON.stringify({func : "count", format : "Count: %i"})
, editable : "text"
}).css('width','250px');
$("#table1").find("th[field='progress']").attr({
total : JSON.stringify({func : "sum", format : "Total: <div style='float:right'>%i</div>"})
, filter : "gt"
}).click(function(){
// $("#table1").trigger('sort', ['progress', 'numeric']);
$("#table1").trigger('sort', ['progress', 'numeric']);
});
$("#table1").find("th[field='status']").attr({
lookup : '{"0":"No","1":"Yes"}'
, total : "Total"
});
$("#table1").find("th[field='managed']").attr({
lookup : '{"0":"alpha","1":"beta", "2":"gamma", "3":"delta", "4":"epsilon"}'
, filter : "lookup"
, editable : "state" // dropdown | text (default)
}).click(function(){
$("#table1").trigger('sort', 'managed');
});
$("#table1").better('table');
// $("#table1").find("th[field='managed']").get(0).applyFilter();
</script>