Auto-Sorting
Auto-Sorting
techguy1988
Posts: 27Questions: 0Answers: 0
Hi,
I was wondering if there was an auto-sorting for a date in the following format ... DD/MM/YYYY. I understand there is one for DD/MM/YY but I would like to show the full year.
Can anyone help me out with this?
Many thanks.
I was wondering if there was an auto-sorting for a date in the following format ... DD/MM/YYYY. I understand there is one for DD/MM/YY but I would like to show the full year.
Can anyone help me out with this?
Many thanks.
This discussion has been closed.
Replies
Allan
All I am using is a normal date like dd/mm/yyyy.
I am also noticing that with commas the currency is not displaying in descending order correctly. i.e. 1,000, should appear before 800, but for some reason 1,000 shows last!?
For the comma issue, have a look at this plug-in: http://datatables.net/plug-ins/sorting#formatted_numbers . 1,000 isn't strictly an integer, it's a string with alphanumerics in it, so it isn't automatically picked up as a number. The formatted numbers plug-in allows it to be sorted as would be expected.
Allan
Thanks for you're help, unfortunately my numbers include a currency symbol and commas! What a disaster! Seems there is no automatic sorting for me.
I've tried a function that someone was using for the date (dd/mm/yyyy) and I was hoping it would "auto" sort it for me, is this the case? Or do I still need to include the sType? I say this because the tables I am building are built off user generated content, so I woulden't be able to know exactly what column number the data was in.
Thanks for you're help.
If you want 'auto sorting' detection, you need to use a type detection plugin - this one for example: http://datatables.net/plug-ins/type-detection#uk_date . The alternative to a automatic type detection is to specify sType.
Allan
I have installed the number's HTML one - I am not sure if this covers commas? But anyway's for some reason it doesn't seem to be working, have you any ideas?
[code]
jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
var x = a.replace( /<.*?>/g, "" );
var y = b.replace( /<.*?>/g, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
jQuery.fn.dataTableExt.aTypes.push( function ( sData )
{
sData = typeof sData.replace == 'function' ?
sData.replace( /<.*?>/g, "" ) : sData;
var sValidFirstChars = "0123456789-";
var sValidChars = "0123456789.";
var Char;
var bDecimal = false;
/* Check for a valid first char (no period and allow negatives) */
Char = sData.charAt(0);
if (sValidFirstChars.indexOf(Char) == -1)
{
return null;
}
/* Check all the other characters are valid */
for ( var i=1 ; i
It would be a massive pain however if I had to go through each of my datatables and add a sorting type!!
[code]
jQuery.fn.dataTableExt.aTypes.unshift( function ( sData )
[/code]
'unshift' rather than 'push' and see if that helps. I have a sneaking suspicion that your code might be being treated as type 'html' by DataTables.
Allan
Sorry but that doesn't work :(
Just doesn't seem to sort anything. P.S. I took the sType bit out to check if it was working.
Allan
It's a closed system (internal) - do you have an email I can send to you for access?
Many thanks.
Allan