Error sorting the numbers in table

Error sorting the numbers in table

JaviVV7JaviVV7 Posts: 2Questions: 1Answers: 0
edited August 2020 in Free community support

http://silentflex.com/tablas/prueba/index

Hello, I have some troubles with my table, it does not sort properly the numbers, in some columns it works fine but in other ones not, for example in the column called "Mt max nm" , you can check in the link of the test that it does not work fine... I tried changing "," with "." and tried adding the "data-order" to the <td> but it does not work so I have no idea about what´s the mistake, can you help me ? Thank you so much:

Here is a picture of the mistake, 85.30 should be over 9.7 for example.

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    You have none number data in that column:

    Datatables will set the column type to string in this case. This is causing the sorting issue. Orthogonal data can be used to fix this. You will need to return zero for the sort and probably the type operations when the value is -. Something like this (I didn't test this so it may need adjustments to work):

        render: function ( data, type, row ) {
            if ( type === 'sort' || type === 'type' ) {
                if (data === '-') {
                  return 0;
                } else {
                 return data;
            }
            return data;
        }
    

    See the similar example in the docs for more info.

    Kevin

  • JaviVV7JaviVV7 Posts: 2Questions: 1Answers: 0

    Thank you so much for your quick answer Kevin, I finally got the solution, it was actually quite stupid...

    The problem was that I had some values with two points, for example "1.085.30" and according to your answer that may transformed the column into string data and because of that the sorting was failing, I just changed them to "1085.30" and it is fine now.

This discussion has been closed.