Sorting troubles
Sorting troubles
Hi,
I seem to have exactly the same problem as posted in "[Sink] Bamboozled over Date sorting" where the author says he needs to put his code directly into the main DataTables js file to get it to work. I have written my own sorter to sort numbers formatted with the thousands separator eg "23,456" (adapted from the example on the website using comma as decimal)
[code]
jQuery.fn.dataTableExt.aTypes.push(
function ( sData )
{
var sValidChars = "0123456789-,.";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i
I seem to have exactly the same problem as posted in "[Sink] Bamboozled over Date sorting" where the author says he needs to put his code directly into the main DataTables js file to get it to work. I have written my own sorter to sort numbers formatted with the thousands separator eg "23,456" (adapted from the example on the website using comma as decimal)
[code]
jQuery.fn.dataTableExt.aTypes.push(
function ( sData )
{
var sValidChars = "0123456789-,.";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i
This discussion has been closed.
Replies
The trick here is that there is an interaction between the numeric and xyz detection. If DataTables find a column which does not fully match a type description, then it falls back to 'string'. And in this case, 'numeric' was being checked first, so any unformatted integers would return 'numeric', but you of course want xyz. As soon as it hits one which doesn't match numeric, but is xyz, it falls back to string!
So you need to make 'xyz' a higher priority. And this is done simply by adding your type detection function to the start of the array, rather than at the end. Array.unshift() does this (although note it won't work in IE6 - a simple array concat will be needed if you want IE6 support). My example has been updated for this.
Regards,
Allan