货币的数据表格式

时间:2016-04-15 06:34:46

标签: javascript php jquery html ajax

我需要在数据表JSON数据中使用逗号格式化货币。但我没有运气,请帮助我。

代码:

listReportByProductCat(function (json) {
    var table = $('#bycat_table').DataTable({
        "columnDefs": [
            { "visible": false, "targets": 1 }
            { "column": num-fmt, "targets": 3 } // PROBLEM HERE
        ],
        "order": [[ 1, 'asc' ]],
        "displayLength": 25,
        "drawCallback": function ( settings ) {
            var api = this.api();
            var rows = api.rows( {page:'current'} ).nodes();
            var last=null;

            api.column(1, {page:'current'} ).data().each( function ( group, i ) {
                if ( last !== group ) {
                    $(rows).eq( i ).before(
                        '<tr class="group"><td colspan="6"><b>'+group+'</b></td></tr>'
                    );

                    last = group;
                }
            } );
        },
        destroy: true,
        processing: true,
        data: json,
        "columns": [
            { "data": "Prod ID" },
            { "data": "catname" },
            { "data": "Product Name" },
            { "data": "Price" },
            { "data": "Qty" },
            { "data": "Total" }
        ]
    });

所以问题发生在目标上:3,我使用num-fmt跟踪数据表文档,但仍然无效。请帮忙。

1 个答案:

答案 0 :(得分:1)

按照此链接排序格式化数据 https://datatables.net/plug-ins/sorting/#formatted_numbers

 <script type="text/javascript" src="jquery.dataTables.js"></script>
    <script type="text/javascript" src="dataTables.numericComma.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#example').dataTable( {
                "columnDefs": [
                    { "type": "numeric-comma", targets: 3 }
                ]
            } );
        } );
    </script>