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="ammount"><?php echo $row[Ammount]; ?></td>                      
</tr>
<script>
$("tr").find("#ammount").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?

Answer

Try this,

 <script>
        let x = document.querySelectorAll("#ammount"); 
        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>

Leave a Reply

Your email address will not be published. Required fields are marked *