Sort the Date Column in MM/DD/YYYY format
Sort the Date Column in MM/DD/YYYY format
beginner_2018
Posts: 46Questions: 19Answers: 0
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
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
Take a look at the browser's console to see if you are getting any errors.
Kevin