-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.html
More file actions
110 lines (95 loc) · 3.05 KB
/
example.html
File metadata and controls
110 lines (95 loc) · 3.05 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/table.css" />
<script type="text/javascript" src="js/table.js"></script>
<style rel="stylesheet" type="text/css">
body {
background-color: #fff;
font-family: 'PT Sans', sans-serif;
font-stretch: normal;
font-style: normal;
font-variant: normal;
font-weight: normal;
}
button {
height: 30px;
width: 100px;
margin: 10px 0;
cursor: pointer;
}
</style>
<script type="text/javascript">
// Instantiate the table object and define its
var t = new Table({
// id of table to attach to
id: "example",
// Table header fields, data types and classes
fields: {
"Date": {
"class": "edit",
"type": "date"
},
"Meter Read": {
"class": "edit",
"type": "int"
},
"Used kWh": {
"type": "calc",
"formula": [
{ "subtract": [{ "c":-1 }, { "c":-1, "r":-1 }] }
]
},
"Cost": {
"class": "edit",
"type": "money"
},
"Avg kWh / Day": {
"type": "calc",
"formula": [
{ "datediff": [{ "c":-4 }, { "c":-4, "r":-1 }] },
{ "divide": [{ "c":-2 }, { }] }
]
},
"Avg Cost / Day": {
"class": "money",
"type": "calc",
"formula": [
{ "datediff": [{ "c":-5 }, { "c":-5, "r":-1 }] },
{ "divide": [{ "c":-2 }, { }] }
]
}
},
// Table data
data: [
['2014-12-04', '45653', '', '205.26', '', ''],
['2015-02-04', '47017', '', '236.81', '', '']
],
// Position table rows
direction: "desc",
// Enable debug output to console
debug: true
});
$(document).ready(function() {
// Render the table
t.render();
// Add row
$("button#addrow").on("click", function() {
t.addRow();
});
// Serialize
$("button#serialize").on("click", function() {
var data = t.serialize();
alert(JSON.stringify(data));
});
});
</script>
</head>
<body>
<button id="addrow">Add Row</button>
<button id="serialize">Serialize</button>
<table id="example"></table>
</body>
</html>