How to sort on Date Column in DataTable - Answer is

How to sort on Date Column in DataTable - Answer is

pawansoftengrpawansoftengr Posts: 1Questions: 1Answers: 0

Question: How to sort on Date Column in DataTable ?
Answer:
1. Define Column Definition
2. Add Type:Date and Target column as index
3. Example: all the columns having date is added below and they will sort the date.

$(document).ready(function () { $('#TableName').DataTable({ "columnDefs": [ { type: 'date', "targets": [10, 11,12,13,14,16] } ] }); });

Answers

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    Setting the columns.type option should basically never be done manually. If DataTables doesn’t pick it up automatically that your column is a date type, then forcing it to do so will just cause an error in the sorting.

    Perhaps you can give a link to a page showing the issue please?

    Also, of interest, I’m working on a new feature for DataTables 1.12 to make date/time sorting much easier :)

    Allan

  • kthorngrenkthorngren Posts: 21,184Questions: 26Answers: 4,925

    Use the datetime sorting solution presented in this blog.

    Kevin

Sign In or Register to comment.