KoolReport's Forum

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

Add rows in DataTables #791

Closed SOFMAN opened this topic on on Apr 9, 2019 - 3 comments

SOFMAN commented on Apr 9, 2019

I can add rows in a DataTables, I need 3 rows. I need like the example

David Winterburn commented on Apr 11, 2019

Hi,

Please try this process to add the sub total, IVA12 and total rows to your table:

        ->pipe(new \koolreport\processes\Map([
            '{value}' => function($row, $meta, $index, $mapState) {
                $SubTotal = isset($mapState['SubTotal']) ?
                    $mapState['SubTotal'] : [];

                if (! isset($SubTotal['Total'])) {
                    $SubTotal['Precio_Final'] = 'Sub Total';
                    $SubTotal['Total'] = 0;
                }
                $SubTotal['Total'] += 1*$row['Total'];

                $mapState['SubTotal'] = $SubTotal;

                return ['{rows}' => $row, '{state}' => $mapState];
            },
            '{end}' => function($count, $mapState) {
                $SubTotal = $mapState['SubTotal'];
                $IVA12 = [
                    'Precio_Final' => 'IVA12',
                    'Total' => $SubTotal['Total'] * 12/100,
                ];
                $Total = [
                    'Precio_Final' => 'Total',
                    'Total' => $SubTotal['Total'] + $IVA12['Total'],
                ];
                return [
                    $SubTotal,
                    $IVA12,
                    $Total
                ];
            },
        ]))
        ->pipe($this->dataStore('myDataStore'));

Please let us know if there's any problem. Thanks!

SOFMAN commented on Apr 11, 2019

I need the three rows to be on the "footerText" of the table.

David Winterburn commented on Apr 12, 2019

In that case, you probably have to wait till our datatables has the ability to add rows to the footer like you want. 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
None yet

None