forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-editor.html
More file actions
98 lines (90 loc) · 2.63 KB
/
csv-editor.html
File metadata and controls
98 lines (90 loc) · 2.63 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
<!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/jquery.tmpl.js"></script>
<script src="../external/jquery.mousewheel-3.0.4.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.observable.js"></script>
<script src="../ui/jquery.ui.grid.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");
}
}
}
$(function() {
var columns = [],
i, j;
for (i = 65; i <= 70; i++) {
columns.push(String.fromCharCode(i));
}
var source = [{}];
$( "#csvEditor" ).grid({
columns: columns,
source: source
})
.gridEditor()
.navigator()
.grid("refresh");
$( "#addRow" ).click( function() {
$.observable( source ).insert( {} );
});
$( "#export" ).click(function() {
var result = "";
for (j = 0; j < source.length; j++) {
var row = [];
for (i = 0; i < columns.length; i++) {
// TODO proper CSV editor would escape values here
row.push(source[j][columns[i]] || "");
}
result += row.join(",") + "\n";
}
console.log(result);
});
});
</script>
<style>
.ui-grid tr .navigator-active { background: rgba(0,0,255,0.2); }
.ui-grid input { border: none; margin: 0; }
thead td { text-align: center; }
</style>
</head>
<body>
<h1>Grid based custom csv editor (experimental)</h1>
<table id="csvEditor">
<thead>
<tr>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button id="addRow">Add row</button>
<button id="export">Export as CSV (on console for now)</button>
</body>
</html>