如何在数据表中格式化货币? [英] How to format currency in Datatables?

查看:120
本文介绍了如何在数据表中格式化货币?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个显示交易的表格,使用 DataTables 实现.

This is a table which display transactions, implementes using DataTables.

$( document ).ready(function() {    
    var table = $('#tbl_transaksi').DataTable( {
        "ajax": "data_transaksi.php",
        "bPaginate":true,
        "bProcessing": true,
        "pageLength": 10,
        "columns": [
            { mData: 'username' } ,
            { mData: 'fullname' },
            { mData: 'the_date' },
            { mData: 'amount',  render: function ( data, type, row ) {
                return "Rp " + data;
                } 
            }
        ],
        "dom": 'Bfrtip',
        "buttons": [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    }); 

});

有效.现在,我想添加一个增强功能:使用印度尼西亚语格式设置金额("jumlah"),例如, 1000000 将显示为" Rp 1.000.000 ";

It works. Now I want to add an enhancement: format the amount ("jumlah") using Indonesian format, so for example 1000000 will be displayed as "Rp 1.000.000";

通过Google搜索,我找到了渲染器.我将渲染部分添加到我的代码中,并且它不会更改格式.怎么了?

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?

推荐答案

使用$.fn.dataTable.render.number函数

$( document ).ready(function() {    
    var table = $('#tbl_transaksi').DataTable( {
        "ajax": "data_transaksi.php",
        "bPaginate":true,
        "bProcessing": true,
        "pageLength": 10,
        "columns": [
            { mData: 'username' } ,
            { mData: 'fullname' },
            { mData: 'the_date' },
            { mData: 'amount',  render: $.fn.dataTable.render.number( ',', '.', 3, 'Rp' )
            }
        ],
        "dom": 'Bfrtip',
        "buttons": [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    }); 

});

这篇关于如何在数据表中格式化货币?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆