<thead>
<tr>
<th >
</th>
<th>
Empresa
</th>
<th >
POL / POD
</th>
<th>
Data<br/>
Embarque<br/><a onclick="sortByDateDesc()" style="font-size:25px;">⥃</a> <a onclick="sortByDate()" style="font-size:25px;">⥄</a>
</th>
<th >
Viagem
</th>
</tr>
</thead>
<tbody>
<tr> <td>P1</td> <td align=center>LA WEB</td> <td align=center>IGI / MAO</td> <td align=center>25/12/2019</td> <td align=center>BLKR121212</td> </tr> <tr> <td>P2</td> <td align=center>WEB LA</td> <td align=center>MAO / RIG</td> <td align=center>01/02/2019</td> <td align=center>BLKR121212</td> </tr> <tr> <td>P3</td> <td align=center>WEBBER MA</td> <td align=center>MVD / BUE</td> <td align=center>25/10/2019</td> <td align=center>BLKR121212</td> </tr> <tr> <td>P4</td> <td align=center>LAS WEBS</td> <td align=center>STS / USH</td> <td align=center>30/05/2020</td> <td align=center>BLKR121212</td> </tr>
</tbody>
</table>
<script>
function convertDate(d) {
var p = d.split("/");
return +(p[2]+p[1]+p[0]);
}
function sortByDate() {
table = document.getElementById("customers");
//var tbody = document.querySelector("#results tbody");
// get trs as array for ease of use
var rows = [].slice.call(table.querySelectorAll("tr"));
rows.sort(function(a,b) {
return convertDate(a.cells[4].innerHTML) - convertDate(b.cells[4].innerHTML);
});
rows.forEach(function(v) {
table.appendChild(v); // note that .appendChild() *moves* elements
});
}
function sortByDateDesc() {
table = document.getElementById("customers");
//var tbody = document.querySelector("#results tbody");
// get trs as array for ease of use
var rows = [].slice.call(table.querySelectorAll("tr"));
rows.sort(function(a,b) {
return convertDate(b.cells[4].innerHTML) - convertDate(a.cells[4].innerHTML);
});
rows.forEach(function(v) {
table.appendChild(v); // note that .appendChild() *moves* elements
});
}
</script>
Obs / PS -> Original code by https://stackoverflow.com/users/615754/nnnnnn
Nenhum comentário:
Postar um comentário