-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpersonfill.js
More file actions
60 lines (46 loc) · 1.96 KB
/
personfill.js
File metadata and controls
60 lines (46 loc) · 1.96 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
let rowsToMake = 100
// let [headers, rows] = persons(rowsToMake),
let [headers, rows] = persons(rowsToMake, {
/* omitRest: 1,
useId: { preset: 0, chars: ['-',''] },
naming: { form: 'playful', joined: 1 }, genders: 1,
birthdays: 1, age: 1,
origin: { joined: 1 },
status: 1, colors: 1,
creatures: { fantasy: 2, fauna: 1 },
points: 3, quote: 1,
scores: 3, sentence: 1,
timestamp: 1 */
} ),
footers = headers, // cause no special footers for now
tbl = document.querySelector('.sTable').children[0]
// renderTable(tbl, headers, rows, footers)
renderTableBetter(tbl, headers, rows, footers)
function renderTable(tbl, headers, rows, footers=headers) {
tbl.tHead.children[0].innerHTML = !headers? '' :
headers.reduce( (ths, header) => ths + `<th> ${ header } </th>` ,'' )
tbl.tFoot.children[0].innerHTML = !footers? '' : cellsHTML(footers)
tbl.tBodies[0].innerHTML = !rows? '' :
rows.reduce( (trs, row) => trs + `<tr>${ cellsHTML(row) }</tr>`, '' )
function cellsHTML(row) {
return row.reduce( (html, str, i) =>
html + (i? `<td>${ str }</td>` : `<th>${ str }</th>`), '' )
}
}
// just for fun - with color samples (if color column present) and wrap text
function renderTableBetter(tbl, headers, rows, footers=headers) {
const colorColumns = []
tbl.tHead.children[0].innerHTML =
headers.reduce( (ths, header, i) => ths + `<th> ${
!header.includes('color')? header : colorColumns.push(i) && header
} </th>` ,'' )
tbl.tFoot.children[0].innerHTML = cellsHTML(footers)
tbl.tBodies[0].innerHTML = rows.reduce( (trs, row) =>
trs + `<tr>${ cellsHTML(row, colorColumns) }</tr>`, '' )
function cellsHTML(row, colorColumns=[]) {
return row.reduce( (html, str, i) =>
html + (i? `<td ${ str.length>180? 'style=white-space:normal':'' }>
${ str } ${ colorColumns.includes(i)? `<b style=background:${str}
>| |</b>`:'' }</td>` : `<th>${ str }</th>`), '' )
}
}