Sorting
Sorting
juanda
Posts: 1Questions: 0Answers: 0
I have a column with more than one date field inside htm lists.
I would like to order that column based on the first date of each cell.
My test page:
http://www.laboratoriodental.es/test.html (column "Cita").
I tried with custom sorting and adding a new type called "fecha":
[code]
{
"mData": "cita",
"sClass": "valignCenter",
"sWidth": "105px",
"sType": "fecha"
},
[/code]
[code]
function fecha_yyyymmdd(fecha)
{
if ((fecha == '00-00-0000' || fecha == null))
return '';
else
{
var datePart = fecha.match(/\d+/g),
year = datePart[2]//.substring(2), // get only two digits
month = datePart[1], day = datePart[0];
return year + month + day;
}
}
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"fecha-pre": function(a) {
if (a===""||a===null) return 0;
fecha = a.substr(8, 10);
fecha = fecha_yyyymmdd(fecha1);
alert(fecha);
return fecha;
},
"fecha-asc": function(a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"fecha-desc": function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
[/code]
I don't really know what the code does because the alert doesn't get fired!
Any idea?
Thank you!
I would like to order that column based on the first date of each cell.
My test page:
http://www.laboratoriodental.es/test.html (column "Cita").
I tried with custom sorting and adding a new type called "fecha":
[code]
{
"mData": "cita",
"sClass": "valignCenter",
"sWidth": "105px",
"sType": "fecha"
},
[/code]
[code]
function fecha_yyyymmdd(fecha)
{
if ((fecha == '00-00-0000' || fecha == null))
return '';
else
{
var datePart = fecha.match(/\d+/g),
year = datePart[2]//.substring(2), // get only two digits
month = datePart[1], day = datePart[0];
return year + month + day;
}
}
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"fecha-pre": function(a) {
if (a===""||a===null) return 0;
fecha = a.substr(8, 10);
fecha = fecha_yyyymmdd(fecha1);
alert(fecha);
return fecha;
},
"fecha-asc": function(a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"fecha-desc": function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
[/code]
I don't really know what the code does because the alert doesn't get fired!
Any idea?
Thank you!
This discussion has been closed.