Having trouble with dateformat dd.mm.yyyy
Having trouble with dateformat dd.mm.yyyy
Hi
I'm trying to sort the data format: dd.mm.yyyy
I'm using the following code:
[code]
/* Note 'unshift' does not work in IE6. A simply array concatenation would. This is used
* to give the custom type top priority
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789-,";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable();
} );
[/code]
Link to where I'm trying to do the sorting: http://oraculum.catonett.com/teamactivity/behandletur.php
I'm trying to sort the data format: dd.mm.yyyy
I'm using the following code:
[code]
/* Note 'unshift' does not work in IE6. A simply array concatenation would. This is used
* to give the custom type top priority
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789-,";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable();
} );
[/code]
Link to where I'm trying to do the sorting: http://oraculum.catonett.com/teamactivity/behandletur.php
This discussion has been closed.
Replies
And that should do it :-)
Allan
Thank you for your reply.
I'm learning javascript, but do still have a way to go ;)
I've modified like this, but still not working. I'm not quite sure if there is anywhere where I should replace / with .
[code]
/* Note 'unshift' does not work in IE6. A simply array concatenation would. This is used
* to give the custom type top priority
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789-,";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d$/))
{
return 'uk_date';
}
return null;
}
);
$(document).ready(function() {
$('#deltakere2').dataTable();
} );
[/code]
Allan
I've changed the code to the following, but still without success.
[code]
/* Note 'unshift' does not work in IE6. A simply array concatenation would. This is used
* to give the custom type top priority
*/
jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d$/))
{
return 'uk_date';
}
return null;
}
);
$(document).ready(function() {
$('#deltakere2').dataTable();
} );
[/code]
I used the following code to sort date with format dd.mm.yyyy (ex. 24.05.2012)
[code]
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/^(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19|20|21)\d\d$/))
{
return 'uk_date';
}
return null;
}
);
jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
var ukDatea = a.split('.');
var ukDateb = b.split('.');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable();
} );
[/code]
I hope this will help others with same issues.