How can I sort using a column with euro currency values?
How can I sort using a column with euro currency values?
diegomartinez
Posts: 4Questions: 2Answers: 0
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 €</td></tr>
<tr><td>1</td> <td>15.65 €</td></tr>
<tr> <td>2</td> <td>8.15 €</td></tr>
<tr> <td>3</td> <td>1.00 €</td></tr>
<tr> <td>4</td> <td>0.3 €</td></tr>
</tbody>
</table>
</body>
</html>
But does not work. Any hint?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
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
Thank you, that was indeed the problem.
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?
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