-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
186 lines (158 loc) · 7.19 KB
/
index.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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>fin-hypergrid JSON Standalone Demo</title>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<script src="bower_components/accountingjs/accounting.min.js"></script>
<link rel="import" href="http://openfin.github.io/fin-hypergrid/components/fin-hypergrid/fin-hypergrid.min.html">
<style>
fin-hypergrid {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
}
</style>
</head>
<body unresolved fullbleed>
<fin-hypergrid class="abs" id="json-example">
<fin-hypergrid-behavior-json></fin-hypergrid-behavior-json>
</fin-hypergrid>
<script>
//setup random data for the JSON tab example
(function(){
var seed = 1;
var rnd = function() {
var x = Math.sin(seed++)*10000;
var r = x - Math.floor(x);
return r;
};
var numRows = 100000;
var firstNames = ['Olivia', 'Sophia', 'Ava', 'Isabella', 'Boy', 'Liam', 'Noah', 'Ethan', 'Mason', 'Logan', 'Moe', 'Larry', 'Curly', 'Shemp', 'Groucho', 'Harpo', 'Chico', 'Zeppo', 'Stanley', 'Hardy'];
var lastNames = ['Wirts', 'Oneil', 'Smith', 'Barbarosa', 'Soprano', 'Gotti', 'Columbo', 'Luciano', 'Doerre', 'DePena'];
var months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
var days = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'];
var states = ['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming'];
var randomFunc = Math.random;
//var randomFunc = rnd;
var randomPerson = function() {
var firstName = Math.round((firstNames.length - 1) * randomFunc());
//var lastName = 'a' + randomFunc() + 'b';
var lastName = Math.round((lastNames.length - 1) * randomFunc());
var pets = Math.round(10 * randomFunc());
var birthyear = 1900 + Math.round(randomFunc() * 114);
var birthmonth = Math.round(randomFunc() * 11);
var birthday = Math.round(randomFunc() * 29);
var birthstate = Math.round(randomFunc() * 49);
var residencestate = Math.round(randomFunc() * 49);
var travel = randomFunc() * 1000;
var income = randomFunc() * 100000;
var employed = Math.round(randomFunc());
var person = {
last: lastNames[lastName],
first: firstNames[firstName],
pets: pets,
birthdate: birthyear + '-' + months[birthmonth] + '-' + days[birthday],
birthstate: states[birthstate],
residencestate: states[residencestate],
employed: employed === 1,
income: income,
travel: travel
};
return person;
};
var headers =
[
'last',
'first',
'pets',
'birth date',
'birth state',
'residence state',
'employed',
'income',
'travel'
];
var fields =
[
'last',
'first',
'pets',
'birthdate',
'birthstate',
'residencestate',
'employed',
'income',
'travel'
];
//lets make it available
data = [];
for (var i = 0; i < numRows; i ++) {
data.push(randomPerson());
}
var editorTypes = ['choice','textfield','spinner','date','choice','choice','choice','textfield','textfield'];
document.addEventListener('polymer-ready', function() {
//get ahold of our json grid example
var jsonGrid = document.querySelector('#json-example');
//get it's table model
var jsonModel = jsonGrid.getBehavior();
//get the cell cellProvider for altering cell renderers
var cellProvider = jsonModel.getCellProvider();
//set the header labels
jsonModel.setHeaders(headers);
//set the fields found on the row objects
jsonModel.setFields(fields);
//set the actual json row objects
jsonModel.setData(data);
//sort ascending on the first column (first name)
// jsonModel.toggleSort(0);
//all formatting and rendering per cell can be overridden in here
cellProvider.getCell = function(config) {
var renderer = cellProvider.cellCache.simpleCellRenderer;
config.halign = 'left';
var x = config.x;
if (x === 2) {
config.halign = 'center';
} else if (x === 3) {
config.halign = 'center';
} else if (x === 6) {
config.halign = 'center';
} else if (x === 7) {
var travel = 60 + Math.round(config.value*150/100000);
var bcolor = travel.toString(16);
config.halign = 'right';
config.bgColor = '#00' + bcolor + '00';
config.fgColor = '#FFFFFF';
config.value = accounting.formatMoney(config.value);
} else if (x === 8) {
var travel = 105 + Math.round(config.value*150/1000);
var bcolor = travel.toString(16);
config.halign = 'right';
config.bgColor = '#' + bcolor+ '0000';
config.fgColor = '#FFFFFF';
config.value = accounting.formatMoney(config.value, "€", 2, ".", ",");
}
renderer.config = config;
return renderer;
};
//lets override the cell editors, and configure the drop down lists
jsonModel.getCellEditorAt = function(x, y) {
var type = editorTypes[x];
var cellEditor = this.grid.cellEditors[type];
if (x === 0) {
cellEditor.items = lastNames;
} else if (x === 4 || x === 5) {
cellEditor.items = states;
} else if (x === 6) {
cellEditor.items = [true, false];
}
return cellEditor;
};
});
})();
</script>
</body>
</html>