Date-Plugin enhancement

Date-Plugin enhancement

rethusrethus Posts: 4Questions: 0Answers: 0
edited July 2012 in Plug-ins
I have a little enhancement of the Plugin from Robert Sedovšek on this Page here (http://datatables.net/plug-ins/sorting#functions_type).
If the Date-Field is empty in the Table, the plugin breaks.

With a little
if (date.length > 0 )
{
//do all the stuff
}

it works quite well again.


Complete Sourcecode here:

[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-eu-pre": function ( date ) {
var date = date.replace(" ", "");

if(date.length > 0){


if (date.indexOf('.') > 0) {
/*date a, format dd.mn.(yyyy) ; (year is optional)*/
var eu_date = date.split('.');
} else {
/*date a, format dd/mn/(yyyy) ; (year is optional)*/
var eu_date = date.split('/');
}
/*year (optional)*/
if (eu_date[2]) {
var year = eu_date[2];
} else {
var year = 0;
}

/*month*/
var month = eu_date[1];
if (month.length == 1) {
month = 0+month;
}

/*day*/
var day = eu_date[0];
if (day.length == 1) {
day = 0+day;
}
}
return (year + month + day) * 1;
},

"date-eu-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"date-eu-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Nice addition - thanks!

    The Plug-ins are all kept in this git repo: https://github.com/DataTables/Plugins . Don't suppose you fancy adding a pull request with your change? :-)

    Allan
This discussion has been closed.