Edit DATATABLE of JQUERY

1

I have a DataTable filled with a query, the problem is that in the database I do not have as many zeros as it shows in DataTable

How can I remove them?

In addition to this how can I edit some characteristics of DataTable . The results are shown as follows:  

The query is simple, the code is below:

    <?php 

session_start();

if(isset($_SESSION['usuario'])){
    require 'vistas/catalogo.view.php';
}else{
    header('location:servicios.php');
}
    //if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        try {
            $servidor='(LOCAL)';
            $base='dbsav300';
            $usuario='XXX';
            $password='XXXXX';

            $conexion=new PDO ("sqlsrv:server=$servidor;Database=$base", "$usuario", "$password");
            echo "Conexion establecida";
        } catch (Exception $e) {
            echo "Error en la conexion:" .$e->getMessage(). "\n";
            exit;
        }

        $consulta=$conexion->prepare('SELECT art_Clave, art_Nombre, art_Total, art_Existencia FROM tArticulo');
        $consulta->execute();

        echo "<table id='table_id' class='display'>";
        echo "<thead>";
        echo "<tr>";
        echo "<th>SKU</th>";
        echo "<th>NOMBRE</th>";
        echo "<th>PRECIO DE VENTA</th>";
        echo "<th>EXISTENCIA</th>";
        echo "</tr>";
        echo "</thead>";

        echo "<tbody>";
        while ($row=$consulta->fetch()) {
            //print_r($row);
            echo "<tr>";
            echo '<th>'.$row['art_Clave'].'</th>';
            echo '<th>'.$row['art_Nombre'].'</th>';
            echo '<th>'.$row['art_Total'].'</th>';
            echo '<th>'.$row['art_Existencia'].'</th>';
            echo "</tr>";
        }
        echo "</tbody>";
        echo "</table>";


 ?>

And the function I call it like this:

<script type="text/javascript">
    $(document).ready( function () {
        $('#table_id').DataTable();
        } );
    </script>

The funny thing that in another part of the page made the same query and is shown correctly:

    
asked by Guillermo Ricardo Spindola Bri 29.07.2016 в 18:56
source

1 answer

1

To format the numbers we use number_format() example:

//Aquí te va dar con dos decimales, cambia el numero de acuerdo 
//a los decimales que necesites

     echo "<tr>";
                echo '<th>'.$row['art_Clave'].'</th>';
                echo '<th>'.$row['art_Nombre'].'</th>';
                echo '<th>'.number_format($row['art_Total'],2).'</th>'; 
                echo '<th>'.number_format($row['art_Existencia'],2).'</th>';
                echo "</tr>";

And to format the table you can use the bootstrap libraries 1 link for datatable and in the function specify what is needed Example:

<script type="text/javascript">
    $(document).ready( function () {
        $('#table_id').DataTable({
          'bPaginate': true, //Para paginar la tabla
         });
        } );
    </script>
    
answered by 29.07.2016 в 22:59