数据表显示数字和列总和,点作为千位分隔符,逗号作为小数点分隔符

时间:2021-02-17 15:49:52

标签: php ajax datatable

我正在使用数据表来显示费用金额和汇总列,这是有效的,但我想使用点作为千位分隔符和逗号作为小数点分隔符来显示金额和总和。这是我的代码:

<!DOCTYPE html>
<html>
<style type="text/css">

    
</style>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
           <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>            
           <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" /> 
    
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <h3 align="center">E X P E N S E&nbsp;&nbsp;&nbsp;&nbsp;L I S T </h3>  
      <table class="table display table-hover table-condensed table-striped table-bordered" id="example" >
          <thead style="text-align: center; background-color: #01caca;color: white; font-weight: bold;">
              <tr>
                  <th style="text-align:center">
                      Account
                  </th>
                  <th style="text-align:center">
                        Month Year
                  </th>
                 <th  style="text-align:center">
                       Amount
                  </th>
                  <th  style="text-align:center">
                       Amount in USD
                  </th>
              </tr>
          </thead>
          <tfoot>
              <tr>
                  <th style="text-align:left">
                   Total
                  </th>
                  <th style="text-align:center">

                  </th>
                  <th style="text-align:center">
                  
                  </th>
                  <th style="text-align:center">
                  
                  </th>
              </tr>
          </tfoot>
         <tbody>
         <?php
                include "dbconnection.php";
                $sql = $connect->query( "SELECT * FROM  expensemonthly,accounts,exchange WHERE expensemonthly.account_id=accounts.account_id ORDER BY expensemonthly.account_id");  
                while ($row=$sql->fetch_array()) {
            ?>
                <tr >
                    <td style="text-align:left"><?php echo   $row[name] ?> </td>
                    <td style="text-align:center"><?php echo $row[yearmonth] ?></td>
                    <td style="text-align:center"><?php echo $row[amount] ?> </td>  
                    <td style="text-align:center"><?php echo $row[amount]*$row[rate]?> </td>

                </tr>
            <?php 
            }
            ?>       
  
         </tbody>
        
      </table>
    </div>
  </body>
</html>
  <script type="text/javascript" language="javascript" >
      var editor; 

        $(document).ready(function() {
            var table = $('#example').DataTable(
        {

            "footerCallback": function ( row, data, start, end, display ) {
                var api = this.api();
                nb_cols = api.columns().nodes().length;
                var j = 2;
                while(j < nb_cols){
                    var pageTotal = api
                .column( j, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return Number(a) + Number(b);
                }, 0 );
          // Update footer
          $( api.column( j ).footer() ).html(pageTotal);
                    j++;
                } 
            }
        }
    );
        });

 
</script>

我附上了一张显示我的代码输出的图像(红色的是数字格式)。 我不知道该怎么做,请问有什么想法吗? enter image description here

0 个答案:

没有答案
相关问题