I have a column which is calculated based on another date column to show in a years/months/days format. I also want this column to be sorted as the date column but since it's a string it is sorting differently.

Here is my code to for datatable config.
"columnDefs": [{ // set default column settings
'orderable': false,
'targets': [1, 9]
}, {
"searchable": false,
"targets": [1, 9]
}],
"order": [
[5, "asc"]
] // set first column as a default sort by asc
Is there any way I can attach the sort for column 6 "At Work" to column 5?
Thanks for the help..
Ok found the answer to the question.
Datatable provide a way to sort orthogonal data by letting you add data-order which will determine the sort order rather then the value contained by the table cell.
Below is the example (from dataTable documentation) which suggests how to do it :)
<tr>
<td data-search="Tiger Nixon">T. Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td data-order="1303682400">Mon 25th Apr 11</td>
<td data-order="3120">$3,120/m</td>
</tr>
So in my case I have to add timestamp to table cell using data-order to sort it correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With