Aoni Mime
Aoni Mime

Reputation: 43

Jquery Render currency from table data

This is a table which display transactions:

enter image description here

<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

Answers (1)

Rin
Rin

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

Related Questions