KoolReport's Forum

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

How could I use thousand coma separations #1805

Open Ali opened this topic on on Dec 29, 2020 - 4 comments

Ali commented on Dec 29, 2020

I have two questions :

1- I just need a comma separator, for Datatable type is RowGroup

DataTables::create(array(
            "dataSource"=>$this->dataStore("invoice_details"),
            "themeBase"=>"bs4", // Optional option to work with Bootsrap 4
            "cssClass"=>array(
                "table"=>"table table-striped table-bordered"
            ),
            "columns" => ["Dated","salesman", "Party", "invoice_no", "iteme_code","Desctiption", "Unit", "Qty", "Amount"],
            "fastRender" => true,
            "clientRowGroup" => [
                "Dated" => [
                    'direction' => 'asc',
                    'calculate' => [
                        'totalSales' => [
                            'sum',  //'sum', 'count', 'avg', 'min', 'max'
                            'Amount',
                            "format" => "function(value) {return value.thousandSeparator(',');}", //here is my problem 
                        ],
                    ],
                    "top" => "<td colspan='999'>{expandCollapseIcon} Top: Date: {Dated} | Total: {totalSales}</td>",
                    "bottom" => "<td colspan='999'>{expandCollapseIcon} Bottom: Date: {Dated} | Customer sales: {totalSales}</td>",
                ],
.
.
.
));

2- my second question: I need to display count distinct of invoice_no

 'countSales' => [
                                'count', 'invoice_no'
                        ],
David Winterburn commented on Dec 30, 2020

Hi Ali,

Regarding your questions for DataTables' clientRowGroup:

1 . Please try this format function:

                    'totalSales' => [
                        'sum',  //'sum', 'count', 'avg', 'min', 'max'
                        'Amount',
                        "format" => "function(value) {return (1*value).toLocaleString();}" 
                    ],

2 . Please try this custom countDistinct function:

                    'countDistinct' => [
                        'field' => 'myColumn',
                        "aggregate" => "function(rows, group, aggFieldIndex) {
                            var initAgg = {
                                values: {},
                                count: 0
                            };
                            return rows
                            .data()
                            .pluck(aggFieldIndex)
                            .reduce( function (agg, b) {
                                if (agg.values[b] !== true) {
                                    agg.count += 1;
                                    agg.values[b] = true;
                                } 
                                return agg;
                            }, initAgg)",
                        "format" => "function(agg) {return agg.count;}",
                    ],

Let us know if there's any problem. Thanks!

Ali commented on Dec 30, 2020

Hi, I put the custom function as you said inside my code but did not work


                        'countSales' => [
                            'count', 'invoice_no',
                        ],
                        'countDistinct' => [
                            'field' => 'invoice_no',
                            "aggregate" => "function(rows, group, aggFieldIndex) {
                            var initAgg = {
                                values: {},
                                count: 0
                            };
                            return rows
                            .data()
                            .pluck(aggFieldIndex)
                            .reduce( function (agg, b) {
                                if (agg.values[b] !== true) {
                                    agg.count += 1;
                                    agg.values[b] = true;
                                } 
                                return agg;
                            }, initAgg)",
                            "format" => "function(agg) {return agg.count;}",
                        ],

                        .
                        .
                        .
                      "top" => "<td colspan='999'>{expandCollapseIcon} Top: Line: {salesman} | Total: {totalSales} | Total Qty: 
                        {total_qty} | Count: {countSales} | countDistinct:{countDistinct} </td>",

any help?

David Winterburn commented on Dec 30, 2020

Oh, the "aggregate" function lacks a closing curly brace "}". Use this please:

                            'countDistinctLine' => [
                                'field' => 'dollar_sales',
                                "aggregate" => "function(rows, group, aggFieldIndex) {
                                    var initAgg = {
                                        values: {},
                                        count: 0
                                    };
                                    return rows
                                    .data()
                                    .pluck(aggFieldIndex)
                                    .reduce( function (agg, b) {
                                        if (agg.values[b] !== true) {
                                            agg.count += 1;
                                            agg.values[b] = true;
                                        } 
                                        return agg;
                                    }, initAgg)}", // } added at the end
                                "format" => "function(agg) {return agg.count;}",
                            ],    
Ali commented on Dec 30, 2020

thank you everything is working.

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
solved

None