Bug when sorting data

Bug when sorting data

anxiousanxious Posts: 11Questions: 0Answers: 0
edited April 2010 in Bug reports
Hello, everything is worked as wanted exept for one thing :

you should have a look at http://www.gamer-certified.fr/statistiques/recapitulatif.php
to understand : look the value

gl-serv 13 96%
crystal-serv 31 96.5%


96% is higher ranked than the 96.5%

is that a bug or did i missed somthing ?

PS: it doesn't happend to others data with float value
Thanks

Replies

  • pimperishpimperish Posts: 17Questions: 0Answers: 0
    How are you specifying the table and the data? If your table values are defined with the '%' sign, then the column probably isn't being recognized as a number field, but rather as a string. If that's the case there's probably at least a couple things you could do. (1) you could write sort and type detection plugins to handle the data or (2) you could only specify the numeric data in the table and use a custom render function (which I assume you're already using since you have the rating images in the column) to add the '%'
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    edited April 2010
    unfortunatly this is out of my skills

    i guess you're rigth because before i begin to use the STAR rendering, there were no problem.
    (1) is not an option (2) is over my skill :P

    can't i force the column to be detected as a number type ?

    I removed the symbol "%" but it's still nor working,

    here how are set the column :
    [code]'.$average*2 .'
    '.$average.'// to display the stars according to the $average value
    [/code]

    here's the table options :

    [code]
    $('#recap').dataTable( {
    "bPaginate": false,
    "aaSorting": [[ 1, "desc" ], [3,'desc']],},
    "bJQueryUI": true,
    "sPaginationType": "full_numbers"
    });

    });
    [/code]

    thanks
  • pimperishpimperish Posts: 17Questions: 0Answers: 0
    Ah, okay, so you could write a custom render function then that would be something like

    [code]
    $('#recap').dataTable( {
    "bPaginate": false,
    "aaSorting": [[ 1, "desc" ], [3,'desc']],},
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "aoColumns": [
    null,
    null,
    null,
    { "fnRender": function(oObj) {
    return oObj.aData[3] + "%";
    }
    },
    null,
    null,
    null,
    null
    ]
    });
    [/code]

    or something like that. This is basically using the column configuration shown here: http://datatables.net/usage/columns#fnRender. It allows you to just put your raw data in the table, but have it displayed in a fancier way.

    so your table would then only be:
    [code]
    '.$average*2 .'
    [/code]
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    edited April 2010
    thank you,
    i'll test it ASAP
  • pimperishpimperish Posts: 17Questions: 0Answers: 0
    oh, I forgot, along with setting "fnRender" for the object in that column, you'll need to set "bUseRendered": false. This will tell datatables to use the raw data to sort/filter on instead of the rendered data.
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    edited April 2010
    even with the bUseRendered i set here :

    [code]
    "bJQueryUI": true,
    "bUseRendered": false,
    "aoColumns": [
    null,
    null,
    null,
    { "fnRender": function(oObj) {
    return oObj.aData[3] + "%";
    }
    },
    null,
    null,
    null,
    null
    ],

    [/code]

    It's still not working, i mean, the stars are correctly shown with the correct values, but it's like there is no data in that column (average displayed as 'moyenne' in my website) cause i can't sort it
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    After seeing the "bUseRendered" in the doc, i set it in the right place and it worked. Thank you very much ;)
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    but the stars no longer works by doing this :/
    =''(
  • pimperishpimperish Posts: 17Questions: 0Answers: 0
    What's the problem with them? on the site you mentioned, they look okay.
  • anxiousanxious Posts: 11Questions: 0Answers: 0
    yes, because i removed your fix because with it, the stars are showing but at defaults values (i mean 5 stars for everyone) unless the average is correctly shown.

    Do you have any idea ?

    Thank you for your help ;)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This is not a bug, but rather DataTables detecting your percentage numbers as a string (since they aren't numbers - they have a % in them). You can use the percentage plug-in from jonathan to help with this:
    http://datatables.net/plug-ins/sorting#percentage

    Allan
This discussion has been closed.