Problems sorting data with decimals in it?

Problems sorting data with decimals in it?

owlowl Posts: 4Questions: 0Answers: 0
edited January 2011 in Plug-ins
Hi

I'm using datatables alot at a site of mine and I have a small issue with it

First of all browse to this site:
http://www.oemautomatic.se/264031-320933.html

Login top right corner with user: datatables and password datatables.
When the site is loaded you will notice a green button saying "Best

Replies

  • 28.vivek.s28.vivek.s Posts: 69Questions: 0Answers: 0
    have you included plugin for numeric-comma?
  • owlowl Posts: 4Questions: 0Answers: 0
    Yeah, here at the bottom.
    http://www.oemautomatic.se/jquery/jquery.dataTables.js

    So its loaded before the datatable which is in:
    http://www.oemautomatic.se/jquery/jquery.wipcore.js
  • 28.vivek.s28.vivek.s Posts: 69Questions: 0Answers: 0
    no i am not talking about this , i mean while defining your table you have written

    [code]{ "sSortDataType": "dom-text", "sType": "numeric-comma" },[/code]

    so try to copy paste this code in your js and see how its going now
    [code]
    jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = 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.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));
    };
    [/code]

    and see this for more info http://www.datatables.net/plug-ins/sorting#numeric_comma
  • owlowl Posts: 4Questions: 0Answers: 0
    Yeh, and I have already done that here: http://www.oemautomatic.se/jquery/jquery.dataTables.js

    Or does it need to be in separate file?
  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Hi owl,

    What you've done is just fine, with the inclusion of the plug-in. However I think the initialisation is slightly off. Try this:

    [code]
    oTable = $('#bestallning').dataTable({
    "bJQueryUI": true,
    "bPaginate": false,
    "bLengthChange": true,
    "bFilter": false,
    "bSort": true,
    "bInfo": false,
    "bAutoWidth": false,
    "sScrollY": "300px",
    "aoColumns": [
    null,
    null,
    { "sType": "numeric-comma" },
    { "sType": "numeric-comma" },
    { "sSortDataType": "dom-text", "sType": "numeric-comma" }
    ]
    });
    [/code]
    You only need to use 'sSortDataType' when you are getting data from a special source - like a DOM node.

    Allan
  • owlowl Posts: 4Questions: 0Answers: 0
    Hey Allan

    Unfortunatly that didnt work :/ Im wondering if there is anything conflictingjavascript or something like that.

    By the total 5 columns there is a special hidden column we use for putting out error notices in if something goes wrong. That one does not have a header, might that be something? Also ni each of them there is a hidden input and one of them is visible.

    Any more ideas would make me greatful =)
  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Hi owl,

    So do you actually have 6 columns in the table? To have a hidden column in the table, use bVisible - the number of columns in aoColumns must exactly match what is in the HTML.

    I just add a look but the "Best
This discussion has been closed.