Date Sorting until "-"
Date Sorting until "-"
Hello everyone, happy new year
I am searching for a solution to sort date values which a in a column with other data. There is always a "-" after the date and the date is always the first string in the field. Is there a solution for this problem?
The page can be found here:
http://chogger.de/database/?p=driver&status=inactive
I am searching for a solution to sort date values which a in a column with other data. There is always a "-" after the date and the date is always the first string in the field. Is there a solution for this problem?
The page can be found here:
http://chogger.de/database/?p=driver&status=inactive
This discussion has been closed.
Replies
is not a valid date since the whole string is looked at by default. You will need to create and use a sorting plug-in:
http://datatables.net/development/sorting
http://datatables.net/plug-ins/sorting
Allan
I am not sure how to start, but thank you Allan. I will try it
[code]
// chogger Custom Date Sorting
function chogger_date(date) {
var date = date.slice(0, 10);
if (date.indexOf('.') > 0) {
/*date a, format dd.mn.(yyyy) ; (year is optional)*/
var chogger_date = date.split('.');
} else {
/*date a, format dd/mn/(yyyy) ; (year is optional)*/
var chogger_date = date.split('/');
}
/*year (optional)*/
if (chogger_date[2]) {
var year = chogger_date[2];
} else {
var year = 0;
}
/*month*/
var month = chogger_date[1];
if (month.length == 1) {
month = 0+month;
}
/*day*/
var day = chogger_date[0];
if (day.length == 1) {
day = 0+day;
}
return (year + month + day) * 1;
}
jQuery.fn.dataTableExt.oSort['chogger_date-asc'] = function(a, b) {
x = chogger_date(a);
y = chogger_date(b);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['chogger_date-desc'] = function(a, b) {
x = chogger_date(a);
y = chogger_date(b);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
Allan