-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
65 lines (55 loc) · 1.82 KB
/
script.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
function DataTable(config, data) {
let tableHtml = `<table>
<thead>
<tr>
<th>№</th>
<th>${config.columns[0].title}</th>
<th>${config.columns[1].title}</th>
<th>${config.columns[2].title}</th>
</tr>
</thead>
<tbody>`
console.log(data)
for (let i = 0; i < data.length; i++) {
tableHtml += `<tr>
<td>${i+1}</td>
<td>${data[i].name}</td>
<td>${data[i].surname}</td>
<td>${data[i].age}</td>
</tr>`
}
tableHtml += `
</tbody>
</table>`
console.log(tableHtml)
document.getElementById('usersTable').innerHTML = tableHtml
}
const config1 = {
parent: '#usersTable',
columns: [
{ title: 'Имя', value: 'name' },
{ title: 'Фамилия', value: 'surname' },
{ title: 'Возраст', value: 'age' },
],
}
const users = [
{ id: 30050, name: 'Вася', surname: 'Петров', age: 12 },
{ id: 30051, name: 'Вася', surname: 'Васечкин', age: 15 },
]
DataTable(config1, users)
//create Tabulator on DOM element with id "example-table"
var table = new Tabulator("#example-table", {
// height:auto, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
data:users, //assign data to table
layout:"fitColumns", //fit columns to width of table (optional)
columns:[ //Define Table Columns
{title:"Name", field:"name", width:150},
{title:"Age", field:"age", hozAlign:"left"},
// {title:"Favourite Color", field:"col"},
{title:"Surname", field:"surname", sorter:"string", hozAlign:"center"},
],
});
//trigger an alert message when the row is clicked
table.on("rowClick", function(e, row){
alert("Row " + row.getData().id + " Clicked!!!!");
});