Sort the Date Column in MM/DD/YYYY format
Sort the Date Column in MM/DD/YYYY format
![beginner_2018](https://secure.gravatar.com/avatar/4efd447e3dfed396746ae8abfc69e35c/?default=https%3A%2F%2Fvanillicon.com%2F4efd447e3dfed396746ae8abfc69e35c_200.png&rating=g&size=120)
Dear All,
I had written the below code to sort the Data Column in the format of MM/DD/YYYY . But I find no luck with it.,
Can any one please help me how can I make it
function sortDatePlugin(){
$.fn.dataTable.moment = function (format,locale){
var types = $.fn.dataTable.ext.type;
// Add type detection
types.detect.unshift( function ( d ) {
return moment( d, format, locale, true ).isValid() ? 'moment-'+format : null;
});
// Add sorting method - use an integer for the sorting
types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
return moment( d, format, locale, true ).unix();
};
};
$.fn.dataTable.moment('MM/DD/YYYY');
}
This discussion has been closed.
Answers
Can you link to a test case showing the issue please?
Allan
Allan,
Thanks for your kind hope . Please find the fiddle.
https://jsfiddle.net/spspecalist87/heoo51pu/6/
A few issues there:
sortDatePlugin()
function so it was never loadingD/M/YYYY
rather thanDD/MM/YYYY
since you don't include leading zeros for the day and month parts.$.fn.dataTable.moment()
function on its ownhttps://jsfiddle.net/heoo51pu/9/
Allan
Sir,
It's working fine when I set the row limit to 10 or 50 rows
![](https://datatables.net/forums/uploads/editor/2u/z1y3der6zece.png)
But when I bind the entire data-set or on large amount of data-set to data-table , It is loosing the control to sort the order
![](https://datatables.net/forums/uploads/editor/oe/zvmx7giqnwtt.png)
Take a look at the browser's console to see if you are getting any errors.
Kevin