-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
146 lines (124 loc) · 3.1 KB
/
index.js
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
function init() {
var displayRows = 10;
function createButton(label, fn, newLine) {
var TABLE = document.getElementsByTagName('TABLE')[0];
if (newLine) {
var BR = document.createElement('BR');
TABLE.parentNode.insertBefore(BR, TABLE);
}
var BUTTON = document.createElement('BUTTON');
BUTTON.innerHTML = label;
$(BUTTON).on('mousedown', fn);
TABLE.parentNode.insertBefore(BUTTON, TABLE);
}
/**
* Data source
*/
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars.charAt(Math.round(Math.random() * (chars.length - 1)));
return result;
}
function createData(rows) {
var arr = [];
var arrPart = [];
var str = 'abcdefghijklmnopqrstuvwxyz';
var i;
for (i = 0; i < 100; i++) {
arrPart.push([
i,
randomString(3 * (1 + Math.sin(i)), str),
randomString(3 * (1 + Math.sin(i + 2)), str),
randomString(3 * (1 + Math.sin(i + 4)), str),
randomString(3 * (1 + Math.sin(i + 6)), str),
randomString(3 * (1 + Math.sin(i + 8)), str),
randomString(3 * (1 + Math.sin(i + 10)), str)
]);
}
for (i = 0; i < rows; i++) {
arr.push(arrPart[i % 100]); //clone 100 row chunks until array has size of 100000
}
return arr;
}
createButton('100k rows', function () {
arr = createData(100000);
wt.draw();
});
createButton('1k rows', function () {
arr = createData(1000);
wt.draw();
});
/**
* Page up/down
*/
createButton('Page down', function () {
wt.scrollVertical(displayRows).draw();
}, true);
createButton('Page up', function () {
wt.scrollVertical(-displayRows).draw();
});
/**
* Scroll left/right
*/
createButton('Scroll left', function () {
wt.scrollHorizontal(-100).draw();
});
createButton('Scroll right', function () {
wt.scrollHorizontal(100).draw();
});
/**
* Init Walkontable
*/
var arr = createData(100000);
var wt = new Walkontable({
table: document.getElementsByTagName('TABLE')[0],
async: true,
data: function (row, col) {
return arr[row][col];
},
totalRows: function () {
return arr.length;
},
totalColumns: function () {
return arr[0].length;
},
offsetRow: 0,
offsetColumn: 0,
height: 200,
width: 200,
frozenColumns: [function (row) {
return row + 1
}],
selections: {
area: {
className: 'area',
border: {
width: 1,
color: '#5292F7',
style: 'solid'
}
},
current: {
className: 'current',
border: {
width: 2,
color: '#5292F7',
style: 'solid'
}
}
},
onCellMouseDown: function (event, coords, TD) {
if (wt.selections.area.isSelected(coords, TD) > -1) {
wt.selections.area.remove(coords, TD);
}
else {
wt.selections.area.add(coords, TD);
}
wt.selections.current.clear();
wt.selections.current.add(coords, TD);
wt.draw();
}
});
wt.draw();
}
window.onload = init;