$('th').click(function(){
let table = $(this).parents('table').eq(0)
console.log(table)
let rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()))
this.asc = !this.asc
if (!this.asc){rows = rows.reverse()}
for (var i = 0; i < rows.length; i++){table.append(rows[i])}
})
function comparer(index) {
return function(a, b) {
var valA = getCellValue(a, index), valB = getCellValue(b, index)
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB)
}
}
function getCellValue(row, index){ return $(row).children('td').eq(index).text() }
<table id="table">
<thead>
<tr>
<th>Дата</th>
<th>Просмотров</th>
<th>Визитов</th>
<th>Сеанс</th>
<th>Отказы</th>
<th>Глубина</th>
</tr>
</thead>
<tbody id="trafic">
<tr>
<td>2019-07-23</td>
<td>66</td>
<td>146</td>
<td>18.18</td>
<td>2.21</td>
<td>4.26</td>
</tr>
<tr>
<td>2019-07-24</td>
<td>64</td>
<td>134</td>
<td>23.44</td>
<td>2.09</td>
<td>4.46</td>
</tr>
<tr>
<td>2019-07-18</td>
<td>61</td>
<td>107</td>
<td>13.11</td>
<td>1.75</td>
<td>2.55</td>
</tr>
</tbody>
</table>