Відмінності між версіями «Шаблони заяв та клопотань»

Перейти до навігації Перейти до пошуку
м
м
Рядок 4: Рядок 4:
</head>
</head>
<body>
<body>
<script>
document.addEventListener('DOMContentLoaded', () => {
    const getSort = ({ target }) => {
        const order = (target.dataset.order = -(target.dataset.order || -1));
        const index = [...target.parentNode.cells].indexOf(target);
        const collator = new Intl.Collator(['en', 'ru'], { numeric: true });
        const comparator = (index, order) => (a, b) => order * collator.compare(
            a.children[index].innerHTML,
            b.children[index].innerHTML
        );
       
        for(const tBody of target.closest('table').tBodies)
            tBody.append(...[...tBody.rows].sort(comparator(index, order)));
        for(const cell of target.parentNode.cells)
            cell.classList.toggle('sorted', cell === target);
    };
   
    document.querySelectorAll('.table_sort thead').forEach(tableTH => tableTH.addEventListener('click', () => getSort(event)));
   
});
</script>
<table class="table_sort" width=95% border="1" align="center" style="border-collapse:collapse" cellpadding="3">
<table class="table_sort" width=95% border="1" align="center" style="border-collapse:collapse" cellpadding="3">
<thead>
<thead>