How can I sort using a column with euro currency values?

How can I sort using a column with euro currency values?

diegomartinezdiegomartinez Posts: 4Questions: 2Answers: 0
edited January 2018 in Free community support

I have a table with currency. I want to be able to sort it. The data has the euro sign symbol. I tried this:

<html>
<head>
    <script type="text/javascript"  src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript"  src="js/jquery.dataTables.min.js"></script>
    <script type="text/javascript"  src="js/currency.js"></script>     
</head>
<body>
<script>
$(document).ready(function() {
 var money_table=$('#moneys').DataTable();
 });
</script>

<table id="moneys"> 
<thead>
        <th>id</th>
        <th>chines</th>     
</thead>
<tbody>
    <tr><td>0</td> <td>1.35 &euro;</td></tr>
    <tr><td>1</td> <td>15.65 &euro;</td></tr>
    <tr>    <td>2</td> <td>8.15 &euro;</td></tr>
    <tr>    <td>3</td> <td>1.00 &euro;</td></tr>
    <tr>    <td>4</td> <td>0.3 &euro;</td></tr>
</tbody>
</table>

</body>
</html>

But does not work. Any hint?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Its the space that is causing the issue - that makes it a string and not a number. If you remove the space, it detects the currency and sorts numerically: http://live.datatables.net/remeqinu/1/edit .

    Allan

  • diegomartinezdiegomartinez Posts: 4Questions: 2Answers: 0

    Thank you, that was indeed the problem.

  • diegomartinezdiegomartinez Posts: 4Questions: 2Answers: 0

    deleting the space in the demo shown works, but when loading the data from a JSON, the ordering stops working again. There are no spaces in the json value. Is there something I have to specify on the column data to allow this?

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    No - it should just work automatically. Can you give me a link to a page showing the issue so I can help to debug it please?

    Allan

This discussion has been closed.