-
Notifications
You must be signed in to change notification settings - Fork 18
/
README.html
341 lines (292 loc) · 8.82 KB
/
README.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<h1 id="nested-datatables">Nested-datatables</h1>
<p>jQuery DataTables plugin for rendering nested DataTables in rows. Inner tables are independent of the data and layout from the outer table.</p>
<h3 id="demohttps:andrejgajdos.github.ionested-datatables"><a href="https://andrejgajdos.github.io/nested-datatables/">Demo</a></h3>
<h3 id="jsfiddlehttps:jsfiddle.netandrej_gajdoszu11wk2o37"><a href="https://jsfiddle.net/andrej_gajdos/zu11wk2o/37/">JSFiddle</a></h3>
<h2 id="installation">Installation</h2>
<p>Download the <a href="https://github.com/AndrejGajdos/nested-datatables/archive/master.zip">latest version</a> and include <a href="https://github.com/AndrejGajdos/nested-datatables/blob/master/dist/nested.datatables.js">nested.datatables.min.js</a> file</p>
<h3 id="npm">NPM</h3>
<pre><code>$ npm install nested-datatables
</code></pre>
<h3 id="usage">Usage</h3>
<pre><code class="js">var table = new nestedTables.TableHierarchy('example', data, settings);
table.initializeTableHierarchy();
</code></pre>
<h2 id="methods">Methods</h2>
<h3 id="tablehierarchywrapperiddatasettings">TableHierarchy(wrapperID, data, settings)</h3>
<p>Main NestedTables constructor.</p>
<h4 id="wrapperid">wrapperID</h4>
<p>Type: <code>String</code></p>
<p>ID of a DOM element where will be table hierarchy rendered.</p>
<h4 id="data">data</h4>
<p>Type: <code>Array.<Object></code></p>
<p>Data used for building table hierarchy. Each item consists of property <code>data</code> and property <code>kids</code>, which represents array of child elements.</p>
<p>Check examples below how to define json data.</p>
<h4 id="settings">settings</h4>
<p>Type: <code>Object</code></p>
<p>Settings for jQuery DataTables constructor.</p>
<h3 id=".initializetablehierarchy">.initializeTableHierarchy()</h3>
<p>Build nested table hierarchy.</p>
<h2 id="events">Events</h2>
<h4 id="onshowchildhierarchy">onShowChildHierarchy</h4>
<p>Triggered when a child hierarchy is shown</p>
<pre><code class="js">// '#example' is wrapper ID for table hierarchy
var tableEle = document.querySelector('#example .table');
tableEle.addEventListener('onShowChildHierarchy', function(e) {
console.log(e);
});
</code></pre>
<h4 id="onhidechildhierarchy">onHideChildHierarchy</h4>
<p>Triggered when a child hierarchy is hidden</p>
<pre><code class="js">// '#example' is wrapper ID for table hierarchy
var tableEle = document.querySelector('#example .table');
tableEle.addEventListener('onHideChildHierarchy', function(e) {
console.log(e);
});
</code></pre>
<h2 id="example">Example</h2>
<pre><code class="html"><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="./dist/nested.datatables.min.js"></script>
</head>
<body>
<div id="example" class="container"></div>
<script>
var dataInJson = [
{
data: {
name: 'b1',
street: 's1',
city: 'c1',
departments: 10,
offices: 15
},
kids: [
{
data: {
department: 'HR',
supervisor: 'Isidor Bristol',
floor: 1,
employees: 15
},
kids: [
{
data: {
name: 'Klement Nikodemos',
phone: '+938462',
hire_date: 'January 1, 2010',
id: 3456
},
kids: []
},
{
data: {
name: 'Madhava Helmuth',
phone: '+348902',
hire_date: 'May 23, 2002',
id: 1234
},
kids: []
},
{
data: {
name: 'Andria Jesse',
phone: '456123',
hire_date: 'October 23, 2011',
id: 9821
},
kids: []
}
]
},
{
data: {
department: 'development',
supervisor: 'Jim Linwood',
floor: 2,
employees: 18
},
kids: [
{
data: {
name: 'Origenes Maxwell',
phone: '345892',
hire_date: 'February 1, 2004',
id: 6234
},
kids: []
}
]
},
{
data: {
department: 'testing',
supervisor: 'Zekeriya Seok',
floor: 4,
employees: 11
},
kids: []
}
]
},
{
data: {
name: 'b2',
street: 's10',
city: 'c2',
departments: 3,
offices: 10
},
kids: [
{
data: {
department: 'development',
supervisor: 'Gallagher Howie',
floor: 8,
employees: 24
},
kids: [
{
data: {
name: 'Wat Dakota'
},
kids: []
}
]
},
{
data: {
department: 'testing',
supervisor: 'Shirley Gayle',
floor: 4,
employees: 11
},
kids: []
}
]
},
{
data: {
name: 'b3',
street: 's3',
city: 'c3',
departments: 2,
offices: 1
},
kids: [
{
data: {
department: 'development'
},
kids: [
{
data: {
name: 'Wat Dakota'
},
kids: []
}
]
},
{}
]
},
{
data: {
name: 'b4',
city: 'c4'
},
kids: []
}
];
var settings = {
iDisplayLength: 20,
bLengthChange: false,
bFilter: false,
bSort: false,
bInfo: false
};
var table = new nestedTables.TableHierarchy(
'example',
dataInJson,
settings
);
table.initializeTableHierarchy();
</script>
</body>
</html>
</code></pre>
<h2 id="example2">Example 2</h2>
<pre><code class="html"><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="./dist/nested.datatables.min.js"></script>
</head>
<body>
<div id="example" class="container"></div>
<script>
var dataInJson2 = [
{
data: {
date: '2018-08'
},
kids: [
{
data: {
' ':
'&lt;input type="checkbox" name="exampleCheckbox" value="exampleCheckbox"&gt;',
img:
'&lt;img src=https:\/\/picsum.photos\/100\/100 width=20 \/&gt;',
like: {
value: 47,
cellClass: 'likeCell',
headerClass: 'likeHeader'
},
perf: { value: 130.55555555555554, cellClass: 'perf' },
date: '2018-08-30'
},
kids: []
},
{
data: {
' ':
'&lt;input type="checkbox" name="exampleCheckbox2" value="exampleCheckbox2"&gt;',
img:
'&lt;img src=https:\/\/picsum.photos\/100\/100 width=20 \/&gt;',
like: 24,
perf: 66.66666666666667,
date: '2018-08-31'
},
kids: []
}
]
}
];
var settings = {
iDisplayLength: 20,
bLengthChange: false,
bFilter: false,
bSort: false,
bInfo: false
};
var table = new nestedTables.TableHierarchy(
'example',
dataInJson,
settings
);
table.initializeTableHierarchy();
</script>
</body>
</html>
</code></pre>
<h2 id="license">License</h2>
<p>MIT © <a href="http://andrejgajdos.com">Andrej Gajdos</a></p>
</body>
</html>