Reputation: 43
This is a table which display transactions:
<tr>
<td><?php echo $row[id]; ?></td>
<td><?php echo $row[Request_Date]; ?></td>
<td><?php echo $row[Partner]; ?></td>
<td><?php echo $row[Package]; ?></td>
<td><?php echo $row[Qty]; ?></td>
<td id="amount"><?php echo $row[Amount]; ?></td>
</tr>
<script>
$("tr").find("#amount").each(function() {
var data = $(this).html();
$.fn.dataTable.render.number(',', '.', 2, symbol).display(data);
});
</script>
Now I want to add an enhancement: format the amount using Indonesian format, so for example 25000 will be displayed as "Rp 25.000";
A Google search pointed me to renderers. I added the render part into my code, and well it doesn't change the formatting. What is wrong here?
Upvotes: 2
Views: 140
Reputation: 324
Try this,
<script>
let x = document.querySelectorAll("#amount");
for (let i = 0, len = x.length; i < len; i++) {
let num = Number(x[i].innerHTML)
.toLocaleString('en');
x[i].innerHTML = "Rp "+ num;
x[i].classList.add("currSign");
}
</script>
Upvotes: 1