Column Sorting US date format
Column Sorting US date format

Hi,
I have a column of dates which has this format MM/DD/YYYY. Sorting is not properly working for this format(MM/DD/YYYY). Could you help me?
This discussion has been closed.
Hi,
I have a column of dates which has this format MM/DD/YYYY. Sorting is not properly working for this format(MM/DD/YYYY). Could you help me?
Replies
Are you using the code described in this blog?
Kevin
Also, could you use the debugger so we can see what configuration you are working with.
Allan
Hi,
This is the code and version which one is using in my project.
Reference:
https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js
Js:
function tablesorting() {
$.fn.dataTable.ext.errMode = 'none';
$('#tblClassDetails').DataTable({
"order": [[3, "desc"]],
paging: false,
"searching": false,
"info": false
});
}
Everything is working fine except date column(US format). For example: 2/28/2017, 2/8/2017. It is sorting only based on month.It is not considering the date.
If I use moment.js I'm getting this error. Uncaught TypeError: $.fn.dataTable.moment is not a function at tablesorting
Ref: https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js
JS:
function tablesorting() {
$.fn.dataTable.ext.errMode = 'none';
$.fn.dataTable.moment('M, D, YYYY');
$('#tblClassDetails').DataTable({
"order": [[3, "desc"]],
paging: false,
"searching": false,
"info": false
});
}
You would need to include MomentJS on the page. You also need to change the format to match the data that you are using. Have a read through the link that @kthorngren gave.
Allan
If I use moment.js I'm getting this error. Uncaught TypeError: $.fn.dataTable.moment is not a function at tablesorting
Ref: https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js
JS:
function tablesorting() {
$.fn.dataTable.ext.errMode = 'none';
$.fn.dataTable.moment('M, D, YYYY');
$('#tblClassDetails').DataTable({
"order": [[3, "desc"]],
paging: false,
"searching": false,
"info": false
});
}
Where I have to change the format exactly? I'm new to Jquery. Could you help to change the format?
That is telling DataTables to look for the format
M, D, YYYY
. Which doesn't match your data so you would need to change it to match your format. The full list of options is available in the Moment documentation.Happy to look at a test case showing the issue and help debug it.
Allan