Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,
I have a datatable with 10 columns and the 9th column is date which is to be sorted in descending order. This gets sorted as expected. For a certain condition, the value should be provided with hyperlink. When i provide hyperlink, then it is sorting wrongly.
<td class="tablecntcolum"><a href='.$logFilePath.'target="_new">'.$field_monitor_values[$i[10].'</a></td>


Thenfinal output is something like this :
30-Apr-17
30-Apr-17
15-Sep-16
15-Sep-16
15-Sep-16
15-Sep-16
15-Sep-16
15-Oct-16
05-May-17
05-May-17

What I have tried:

var poltable = $('#pol_table').DataTable( {
       order: [[ 9, 'desc' ]],//sorting based on 9th column
       pageLength: 50,
       autoWidth: true
   });
Posted
Updated 16-Apr-20 19:55pm
v2

Your problem is rather obvious: the sort is perfect! You see date, the computer sees characters.

You need to sort them either in your SQL query before you convert the datetime field to a string (unless you horribly store dates as strings!) or maybe try a more useful date format:

YYYYMMDD will sort correctly as characters . . . that's a numerical month, by the way, or you'll get screwed up again.
 
Share this answer
 
Comments
User1454 24-May-17 0:03am    
Thanks sir. I solved it by changing the date time format to YYYY-MM-DD.
I think in the query it will be wrong.
I was facing same issue because
you should give tablenm.date column name in query LIKE
SELECT * FROM student WHERE id='767' GROUP BY student.id ORDER BY student.date asc
 
Share this answer
 
Comments
CHill60 17-Apr-20 4:18am    
That is SQL and nothing to do with the original question. It also doesn't make any sense

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900