KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Format number #1823

Closed Epitello opened this topic on on Jan 6, 2021 - 7 comments

Epitello commented on Jan 6, 2021

Hi, I have applied a number format styling, but the format is applied only on the first load of the page. Do you have any solution for fix this ? thanks by advance

Epitello commented on Jan 6, 2021

i send you the code

//Assurance.php
<?php
//Permet d'avoir accès au fonctionalité de koolreport
use \koolreport\KoolReport;

//Indique que l'autoload est requis pour le fonctionnement
require_once "../koolreport/core/autoload.php";

//Création d'une class qui recupère les méthodes de Koolreport
class Assurance extends Koolreport{
    //permet d'utiliser les styles de bootstrap
    use \koolreport\bootstrap4\Theme;
    use \koolreport\visualquery\Bindable;

    function settings()
    {
        return array(
            "dataSources"=>array(
                "assurance"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=db_sales",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                ),
            )
        ); 
    }

    protected function setup()
    {
        $params = \koolreport\core\Utility::get($this->queryParams, 'visualquery1');
        $qb = $this->paramsToQueryBuilder($params);
        $this->queryStr = $queryStr = $params ? $qb->toMySQL() : "select departement, nature, compagnie, type, date, montant from koolreport_assurance";
        
        $this
        ->src('assurance')
        ->query($queryStr)
        ->pipe(new \koolreport\processes\ColumnMeta([
            "date" => [
                "type" => "datetime",
                "format" => "d-m-Y"
            ],
            "montant" => [
                "type" => "number",
                "decimals" => 2,
                "decimalPoint" => ".",
                "thousandSeparator" => " "
            ],
        ]))
        ->pipe($this->dataStore('assuranceDS'));
    }
}
//AssuranceView.view.php
<?php
    use \koolreport\visualQuery\VisualQuery;
    use \koolreport\datagrid\DataTables;
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Présentation</title>
    <link rel='stylesheet' href='css/style.css'>
</head>
<body>
    <div class="main-container">
        <form method="post">
            <div class="report-content">
                <div class="text-center">
                    <h1>Présentation</h1>
                </div>
                
                <?php
                VisualQuery::create(array(
                    "name" => "visualquery1",
                    "schema" => array(
                        "tables" => [
                            "koolreport_assurance"=>array(
                                "{meta}" => [
                                    "alias" => "Information générale"
                                ],
                                "departement"=>array(
                                    "alias"=>"Département",
                                ),
                                "nature"=>array(
                                    "alias"=>"Nature",
                                ),
                                "compagnie"=>[
                                    "alias"=>"Compagnie"
                                ],
                                "type"=>[
                                    "alias"=>"Type"
                                ],
                                "date"=>[
                                    "alias"=>"Date"
                                ],
                                "montant"=>[
                                    "alias"=>"Montant",
                                    "type" => "number",
                                    "decimals" => 2,
                                    "decimalPoint" => ".",
                                    "thousandSeparator" => " "
                                ]
                            ),
                        ]
                    ),
                    "defaultValue" => [
                        "selectTables" => [
                            "koolreport_assurance"
                        ],
                        "selectFields" => [
                            "koolreport_assurance.departement",
                            "koolreport_assurance.nature",
                            "koolreport_assurance.compagnie",
                            "koolreport_assurance.type",
                            "koolreport_assurance.date",
                            "koolreport_assurance.montant"
                        ],
                        "filters" => [
                        ],
                        "groups" => [
                        ],
                        "sorts" => [
                        ],
                        "offset" => 0,
                        "limit" => 100,
                    ],
                    "language"=>"fr"
                ));
                ?>
                <div class="padding-perso">
                    <button type='submit' class='btn btn-light btn-perso' >Envoyer</button>
                </div> 

                <?php
                    // print_r($this->dataStore('vqDS')->meta());
                    DataTables::create(array(
                        "name" => "charttable1",
                        "dataSource" => $this->dataStore('assuranceDS'),
                        /* "columns" => [
                            "departement",
                            "nature",
                            "compagnie",
                            "type",
                            "date",
                            "montant"=>[
                                "type"=>"number",
                                "decimals"=>2,
                                "dec_point"=>",",
                                "thousand_sep"=>" ",
                            ]
                        ], */
                        "language"=>'fr',
                        "options" => [
                            "paging" => true
                        ],
                        "cssClass"=>array(
                            "table"=>"table table-striped table-bordered"
                        )
                    ));
                ?>
            </div>
        </form>
        <div class="text-center">
            <p></p>
            <button class="btn btn-primary type-btn" id="doughnut" onclick=''>Ajouter un camembert</button>
            <button class="btn btn-primary type-btn" id="bar" onclick=''>Ajouter un graphique bar</button>
            <p></p>
        </div>

        <div id="drawable-div" class="style-chart row" ></div>
    </div>

    <script src="js/jquery"></script>
    <script src="../koolreport/chartjs/clients/Chart.min.js"></script>
    <script src="js/createChart.js"> </script>
</body>
</html>
Sebastian Morales commented on Jan 7, 2021

Can you print out $queryStr in your report's setup and $this->dataStore('assuranceDS')->meta() in the report's view for both the first load and subsequent submits? We need to see where the difference comes from.

Epitello commented on Jan 21, 2021

$queryStr at the first load :

 'select departement, nature, compagnie, type, date, montant from koolreport_assurance'.

$queryStr at second load :

'SELECT koolreport_assurance.departement AS "Département", koolreport_assurance.nature AS "Nature", koolreport_assurance.compagnie AS "Compagnie", koolreport_assurance.type AS "Type", koolreport_assurance.date AS "Date", koolreport_assurance.montant AS "Montant" FROM koolreport_assurance LIMIT 100 OFFSET 0'

$this->dataStore('assuranceDS')->meta() :

array (size=1)
  'columns' => 
    array (size=6)
      'Département' => 
        array (size=1)
          'type' => string 'string' (length=6)
      'Nature' => 
        array (size=1)
          'type' => string 'string' (length=6)
      'Compagnie' => 
        array (size=1)
          'type' => string 'string' (length=6)
      'Type' => 
        array (size=1)
          'type' => string 'string' (length=6)
      'Date' => 
        array (size=2)
          'type' => string 'date' (length=4)
          'format' => string 'Y-m-d' (length=5)
      'Montant' => 
        array (size=1)
          'type' => string 'number' (length=6)
Sebastian Morales commented on Jan 22, 2021

I forgot one thing, for datetime column the "format" property indicate its original value format so we know how to process it while the one to set how it display is called "displayFormat". For example:

    "date" => array(
        "format" => "Y-m-d H:i:s", //this means the real values of this column is in format `2020-12-30 00:00:00`
        "displayFormat" => "d/m/Y", //this means we want to show this column's values like `30/12/2020`
Epitello commented on Jan 26, 2021

ok but the probleme is for the number type, when i set a southand seperator to " " it's only apply on the first load

Sebastian Morales commented on Jan 27, 2021

Oh I see. I think there's a very small mismatch with the column name "Montant" and the column meta process where "montant" is used. The original reason is because VisualQuery use "alias" property to set the output column name (AS ...) of a query:

    "alias"=>"Montant"

Please change it to:

    "alias"=>"montant"

Then set the column meta's label to "label" => "Montant". Or if you want you could change all "montant" to "Montant" so you don't need to the the column's label later on. Cheers,

Epitello commented on Jan 28, 2021

it's works fine thanks

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

VisualQuery