mixed column with prices order wrong?

mixed column with prices order wrong?

TalieTalie Posts: 6Questions: 2Answers: 0
edited April 2021 in TableTools

it's a mixed column with multiple text elements, not just currency amounts... i can't figure out why the currency amounts aren't sorting properly (for instance $10,000 is showing as higher than $14,000, $6,500 above $7,500). please help!

https://www.ouranch.com/foals-list.php

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    Hi,

    You have non-numeric content in that column as well as the numeric content, which is why it isn’t sorting correctly. I’m using an iPad at the moment, and frustratingly can’t workout how to “view source”, so I can’t see exactly what is going on, but most likely you’ll need to use orthogonal data which will give a numeric value for that column for the sorting information (e.g. sold might be given as 0 or Infinity allowing it to be sorted numerically).

    Allan

  • TalieTalie Posts: 6Questions: 2Answers: 0

    hi Allan. it does seem to be able to recognize/sort the sold/pending/for sale into groups, but for some reason it doesn't seem to recognize the $ amounts and sort them by highest to lowest, which is a bit counter-intuitive. i can't figure it out!

  • TalieTalie Posts: 6Questions: 2Answers: 0
    edited April 2021

    i've tried adding data-order with only the price, thinking perhaps it was confused by the formatting/extra type, and it made no difference.

    i was reading about renderers, and would be happy to edit my current price structure from $X,XXX to XXXX but despite the examples, i can't figure out how (or more importantly WHERE) to fit

    {
        data: 'price',
        render: $.fn.dataTable.render.number( ',', '.', 2, '$' )
    }
    

    into the code! i tried to fit it somewhere into

    <script type="text/javascript" class="init">
    $(document).ready(function() {
    $('#sort').DataTable( {
            "scrollX": true,
            "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
            <?php if ( $youarehere == 'foals' ) {
            echo "\"order\": [[ 2, \"desc\" ]]"; } ?>
        } );
    } );
    </script>
    

    but couldn't get it to work. i'm a designer by trade, not a programmer, so i'm feeling well out of my depth. any assistance would be greatly appreciated.

    (and also, thanks for the reply Allan)

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948
    Answer ✓

    The Natural sorting plugin might work for your data. I copied your table and Datatable config into this test case:
    http://live.datatables.net/nugeyixa/1/edit

    I installed the natural sorting plugin code in the HTML tab and assigned it to the status column. It seems to sort correctly now. Let us know if this works for you.

    Kevin

  • TalieTalie Posts: 6Questions: 2Answers: 0

    Kevin, that did the trick -- thank-you so much for the help (and for dumbing it down for me/showing me the working example!). so very much appreciated!

This discussion has been closed.