Sort table with ratios (10:1)?

Sort table with ratios (10:1)?

gregbarbosagregbarbosa Posts: 2Questions: 1Answers: 0

I'm trying to understand if I can sort a table with a column that contains ratios throughout it. I notice that when it attempts to sort, it'll sort numerically (1-9) ignoring the numbers as hundreds or thousands (1,000 versus 900).

For example:

Column A Column B Column C
Example 1 $10,000,000 1,500:1

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    Its probably sorting as a string. Not really sure how you would want to sort ratios, ie, 1,500:1 versus 1,500:2 but there are a couple options. You can use Orthogonal Data for the sort type to restructure the string to something that sorts as you want. Or you can create a Sorting Plugin. You might find an example here that will help:
    https://datatables.net/plug-ins/sorting/

    Kevin

  • gregbarbosagregbarbosa Posts: 2Questions: 1Answers: 0

    @kthorngren, thank you for that suggestion. It got me looking into those docs and I discovered data-order which allowed me to sort the table as expected and still keep the styling I wanted.

    Sample:
    <td data-order"1500">1,500:1</td>

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    Perfect, glad you got it working.

    Kevin

This discussion has been closed.