-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.js
68 lines (56 loc) · 1.6 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
var data=[
{id:1,name:"Farooq",age:20 },
{id:2,name:"Zakir bhai",age:21 },
{id:3,name:"Suhail bhai",age:22 },
{id:4,name:"gani bhai" ,age:23 },
{id:5,name:"jani bhai",age:24 },
{id:6,name:"money bhai",age:25 },
{id:7,name:"pani bhai" ,age:26 },
{id:8,name:"funny bhai" ,age:27 },
{id:9,name:"gullu bhai" ,age:28 },
{id:10,name:"comedy bhai" ,age:29 }
]
function callfunc(row){
const [first]=data
const keys=Object.keys(first)
const headerrows=createheaders(keys)
console.log(headerrows)
const tablerow=createrows(row)
const container=document.createElement("div")
const filercontainer=document.createElement("div")
keys.forEach(function(col){
const filter=document.createElement("div")
filter.innerHTML=`$<input type="checkbox"/><label>${col}</label>`
filercontainer.appendChild(filter)
})
const table=document.createElement("table")
container.appendChild(table)
document.body.appendChild(container)
table.appendChild(headerrows)
table.appendChild(tablerow)
}
callfunc(data)
function createheaders(headers){
const tr=document.createElement("tr")
headers.forEach(function(i){
const th=document.createElement("th")
th.innerText=i
tr.appendChild(th)
})
return tr;
}
function createrows(rows){
console.log(rows)
const tbody=document.createElement("tbody")
rows.forEach(function(singlerow){
const tr=document.createElement("tr")
const values=Object.values(singlerow)
values.forEach(function(val){
const td=document.createElement("td")
td.innerText=val
tr.appendChild(td)
})
tbody.appendChild(tr)
})
return tbody
}