Using the UK DateTime Plugin

Using the UK DateTime Plugin

pgrajupgraju Posts: 2Questions: 0Answers: 0
edited October 2009 in Plug-ins
Hello all,

I have a table which has the following columns:

- Event Date (is HTML and is formatted like this dd/mm/yyyy hh:mm:ss)
- Event Creator (string)
- Event Body (string)
- Event Type (string)
- Event Progress (string)
- Event Status (string)

I'm trying to use the Date (dd/mm/YYY hh:ii:ss) plugin made by Rohan G. to sort my Event Date but I'm having trouble integrating it. At the moment I initialise the plugin and data tables like so:

[code]
function trim(str) {
str = str.replace(/^\s+/, '');
for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) {
str = str.substring(0, i + 1);
break;
}
}
return str;
}

jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(a, b) {
if (trim(a) != '') {
var frDatea = trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
} else {
var x = 10000000000000; // = l'an 1000 ...
}

if (trim(b) != '') {
var frDateb = trim(b).split(' ');
var frTimeb = frDateb[1].split(':');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;
} else {
var y = 10000000000000;
}
var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
return z;
};

jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(a, b) {
if (trim(a) != '') {
var frDatea = trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
} else {
var x = 10000000000000;
}

if (trim(b) != '') {
var frDateb = trim(b).split(' ');
var frTimeb = frDateb[1].split(':');
frDateb = frDateb[0].split('/');
var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;
} else {
var y = 10000000000000;
}
var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));
return z;
};

$('#datagrid').dataTable({
bAutoWidth: false,
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "euro-date-desc" ]],
"aoColumns": [{"sType": "html"}, null, null, null, null, null]
});
[/code]

I seem to get the following javascript error:

[code]
Error: oSort['html-euro-date-desc'] is not a function
Line: 321
[/code]

Is there something I'm doing wrong here? I'm new to the whole plugin and data table world and any help would be appreciated!

Thanks in advance!

Replies

  • allanallan Posts: 55,884Questions: 1Answers: 8,836 Site admin
    Hi pgraju,

    Just a little bit of a misunderstanding for how to put a sorting plug-in into place. aaSorting shouldn't be used for this (it's values can only be 'asc' or 'desc'), but rather 'sType' should be. So for example:

    [code]
    $('#datagrid').dataTable({
    bAutoWidth: false,
    "sPaginationType": "full_numbers",
    "aoColumns": [{"sType": "euro-date"}, null, null, null, null, null]
    });
    [/code]

    Regards,
    Allan
This discussion has been closed.