Сообщение от MC-XOBAHCK
|
изменить в ней значения
|
так?
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style class="cp-pen-styles">@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700');
body {
font-family: 'Roboto';
}
td, th {
border: 2px solid red;
width: 150px;
height: 40px;
text-align: center;
}
table {
border-collapse: collapse;
margin: 20px auto;
}
th {
cursor: pointer;
}</style>
</head>
<body>
<table class="sort" align="center">
<thead>
<tr>
<th>Name</th>
<th>SecondName</th>
<th>Patronymic</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Макс</td>
<td>Троцкий</td>
<td>Ильич</td>
<td>-7700</td>
</tr>
<tr>
<td>Вася</td>
<td>Петров</td>
<td>Александрович</td>
<td>210000</td>
</tr>
<tr>
<td>Петя</td>
<td>Иванов</td>
<td>Петрович</td>
<td>0</td>
</tr>
<tr>
<td>Миша</td>
<td>Ложкин</td>
<td>Васильевич</td>
<td>1043.006</td>
</tr>
<tr>
<td>Владимир</td>
<td>Сидоров</td>
<td>Игоревич</td>
<td>3.05</td>
</tr>
<tr>
<td>Коля</td>
<td>Колбаскин</td>
<td>Олегович</td>
<td>-41.6</td>
</tr>
</tbody>
</table>
<script>
addEventListener("load", function() {
(function(f) {
function g(c) {
return function(b, a) {
b = b.cells[c].textContent;
a = a.cells[c].textContent;
b = +b || b;
a = +a || a;
return b > a ? 1 : b < a ? -1 : 0
}
}
function init(d) {
const [{cells}, ...e] = [...d.rows];
const tbody = e[0].parentNode;
[...cells].forEach((c, b) => {
var a = 0;
c.addEventListener("click", () => {
e.sort(g(b));
a && e.reverse();
tbody.append(...e);
a ^= 1
})
})
}
document.querySelectorAll(f).forEach(init)
})(".sort")
});
</script>
</body>
</html>