-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
201 lines (187 loc) · 5.94 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paginator-JS</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="dist/theme/paginator.min.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="https://carry0987.github.io/favicon.png" type="image/x-icon">
<style type="text/css">
ul,
li {
list-style: none;
}
#wrapper {
width: 900px;
margin: 20px auto;
}
.data-container {
margin-top: 20px;
}
.data-container ul {
padding: 0;
margin: 0;
}
.data-container li {
margin-bottom: 5px;
padding: 5px 10px;
background: #eee;
color: #666;
}
</style>
</head>
<body>
<div id="wrapper">
<h1 class="text-center">Paginator-JS</h1>
<h3 id="version" class="text-center"></h3>
<p class="text-center">A simple, flexible, customizable and light-weight paginator plugin for the client-side.</p>
<section>
<div class="data-container"></div>
<div id="paginator-demo1"></div>
<div class="data-container"></div>
<div id="paginator-demo2"></div>
<div id="plugin-container"></div>
<div id="paginator-demo3"></div>
<div id="plugin-container-sub"></div>
<div id="paginator-demo4"></div>
</section>
</div>
<script src="dist/paginator.min.js"></script>
<script src="l10n/dist/l10n.min.js"></script>
<script src="plugins/list/dist/list.min.js"></script>
<script src="plugins/table/dist/table.min.js"></script>
<script>
let generateData = (number) => {
let result = [];
for (let i = 1; i < number + 1; i++) {
result.push([i]);
}
return result;
};
let generateObjData = (number) => {
let result = [];
for (let i = 1; i < number + 1; i++) {
result.push({ a: i });
}
return result;
};
const data = generateData(200);
const data2 = generateObjData(100);
// Display version
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#version').textContent = 'v' + paginatorjs.Paginator.version;
});
let paginator1 = new paginatorjs.Paginator({
data: data,
columns: ["Name1"],
pageSize: 10,
pageNumber: 3,
pageRange: 2,
dataRender: (response) => {
let dataHtml = '<ul>';
response.forEach((item, index) => {
dataHtml += '<li>' + item + '</li>';
});
dataHtml += '</ul>';
document.querySelectorAll('.data-container')[0].innerHTML = dataHtml;
}
}).render(document.querySelector('div#paginator-demo1'));
let paginator2 = new paginatorjs.Paginator({
data: data2,
columns: ['a'],
pageSize: 10,
pageRange: 0,
beforeDataLoad: () => {
document.querySelectorAll('.data-container')[1].innerHTML = 'Loading data...';
},
dataRender: (response) => {
let dataHtml = '<ul>';
response.forEach((item, index) => {
dataHtml += '<li>' + item[0] + '</li>';
});
dataHtml += '</ul>';
document.querySelectorAll('.data-container')[1].innerHTML = dataHtml;
}
}).render(document.querySelector('div#paginator-demo2'));
let paginator3 = new paginatorjs.Paginator({
columns: [
{
id: 'name',
name: 'Pokemon',
},
{
id: 'url',
name: 'URL',
formatter: (cell) => cell
}
],
server: {
url: 'https://pokeapi.co/api/v2/pokemon',
param: {
method: 'GET'
},
processData: data => data.results,
total: data => data.count,
pageBody: (prevBody, page, limit) => {
return {
limit: limit,
offset: (page - 1) * limit
};
}
},
pageSize: 5,
pluginContainer: document.querySelector('div#plugin-container'),
plugins: [paginatorjs.plugins.list.listPlugin],
language: paginatorjs.l10n.zhTW
}).render(document.querySelector('div#paginator-demo3'));
paginator3.on('afterPaging', (page) => {
console.log('afterPaging', page);
});
paginator3.on('pageClick', (page) => {
console.log('pageClick', page);
});
let paginator4 = new paginatorjs.Paginator({
columns: [
{
id: 'name',
name: 'Pokemon',
},
{
id: 'url',
name: 'URL',
formatter: (cell) => cell
}
],
server: {
url: 'https://pokeapi.co/api/v2/pokemon',
param: {
method: 'GET'
},
processData: data => data.results,
total: data => data.count,
pageBody: (prevBody, page, limit) => {
return {
limit: limit,
offset: (page - 1) * limit
};
}
},
pageSize: 5,
pluginContainer: document.querySelector('div#plugin-container-sub'),
language: paginatorjs.l10n.zhTW,
className: {
container: 'test-container',
pageButton: 'test-page-button',
prevButton: 'test-prev-button',
nextButton: 'test-next-button',
}
}).render(document.querySelector('div#paginator-demo4'));
paginator4.plugin.add({
id: 'table',
position: paginatorjs.PluginPosition.Body,
component: paginatorjs.plugins.table.Table
});
</script>
</body>
</html>