Ordering Data Column not working
Ordering Data Column not working
I have a table that I want to sort by date, but it is not working.
follow the code.
``` if ( $.fn.dataTable.isDataTable( '#tableabertos' ) ) {
table = $('#tableabertos').DataTable();
table.destroy();
}
$(document).ready(function() {
$('#tableabertos').DataTable({
"order": [[7 , "desc" ]],
"lengthChange": false,
"columnDefs": [ {
"targets": 0,
"orderable": false,
} ]
});
} );
```
HTML
<thead>
<tr>
<th><input type="checkbox" id="all_coletados"/></th>
<th>ATD.</th>
<th>PAC</th>
<th>CON</th>
<th>SE</th>
<th>AG</th>
<th>SL</th>
<th>CL</th>
<th>ST</th>
</tr>
</thead>
<tbody id="tbl_atendimentos_coletados">
<tr>
<td style="text-align: center" scope="row">
<input type="checkbox" pac_nome="Test" atd_cod="199999" pac_sexo="M" dt_nasc="19/08/1932" pac_rg="321654" pac_fone="98762132" pac_carteira="32165465" atd_gih="321654" pac_cnv="ASDF" atd_dthr="13/12/2017 11:36:00" dthr="13/12/2017 15:25:10" id="321654"/>
</td>
<td style="text-align: center">123123</td>
<td>TEST</td>
<td>ASD</td>
<td style="text-align: center"><img src="M.png" height="15px"></td>
<td style="text-align: center">85</td>
<td style="text-align: center">13/12/2017 11:36:00</td>
<td style="text-align: center">13/12/2017 15:25:10</td>
<td style="text-align: center; cursor: pointer;background-color: #ee8 !important; color: black !important;"
onclick="openDetalhes(
'1933145'
)">COLETADO</td>
</tr>
</tbody>
</table>~~~~
This question has an accepted answers - jump to answer
Answers
you need to use the moment.js plugin for sorting:
https://datatables.net/plug-ins/sorting/datetime-moment
here is another discussion thread that might be helpful to get this set up:
https://datatables.net/forums/discussion/comment/116689/
Ty solved!