Приветствую уважаемых форумчан!
Требуется доработка кода сортировки таблицы для работы в старом IE, а именно:
<script type="text/javascript">
'use strict';
const theads = document.querySelectorAll(".table_sort thead");
theads.forEach(thead => thead.addEventListener("click", evt => getSort(evt)));
function getSort({ target }) {
const order = target.dataset.order = -(target.dataset.order || -1);
const thList = Array.from(target.parentNode.cells);
const index = thList.indexOf(target);
const collator = new Intl.Collator(["en", "ru"], { numeric: true });
const comparator = (index, order) => (a, b) => {
return (
order *
collator.compare(a.children[index].textContent, b.children[index].textContent));
};
const tablesBodies = Array.from(target.closest("table").tBodies);
tablesBodies.forEach(tBody => {
tBody.append(...Array.from(tBody.rows).sort(comparator(index, order)));
});
thList.forEach(th => th.classList.toggle("sorted", th === target));
}
</script>
Пример кода таблицы:
<table style="width:99%" class="table_sort">
<thead>
<tr><th>Name</th><th>count1</th><th>count2</th></tr>
</thead>
<tbody>
<tr class="bc"><td>jacques</td><td><b>12</b></td><td>1</td></tr><tr class="bc"><td>mkishimoto</td><td><b>4</b></td><td>5</td></tr><tr class="bc"><td>info</td><td><b>0</b></td><td>2</td></tr><tr class="bc"><td>monika</td><td><b>0</b></td><td>2</td></tr><tr class="bc"><td>sales</td><td><b>0</b></td><td>2</td></tr><tr class="bc"><td>alex</td><td><b>5</b></td><td>0</td></tr><tr class="bc"><td>monika</td><td><b>0</b></td><td>1</td></tr><tr class="bc"><td>bailey</td><td><b>0</b></td><td>1</td></tr><tr class="bc"><td>bansi.v</td><td><b>0</b></td><td>1</td></tr><tr class="bc"><td>dstrupiechowski</td><td><b>2</b></td><td>1</td></tr><tr class="bc"><td>alexx</td><td><b>1</b></td><td>0</td></tr>
</tbody>
</table>
Оплата за выполнение: 50$
PM для связи