KoolReport's Forum

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

Using row dimensions with empty Pivot Table gets error - Undefined array key #2811

Open BrentNJ opened this topic on on Aug 29, 2022 - 6 comments

BrentNJ commented on Aug 29, 2022

Hi,

With an empty pivot table, I get this error

Undefined array key "field1"

When using the row dimensions

->pipe(new Pivot(array(
                'dimensions'=>array(
                    "column"=>"field3",
                    'row'=>'field1, field2'
                ),
                'aggregates'=>array(
                    'count'=>'field4'
                )
            )))

Works ok when query returns data

I did find a related topic https://www.koolreport.com/forum/topics/268 Is a similar solution needed?

Sebastian Morales commented on Aug 31, 2022

Pls post the full error message with error stack trace for us to check it for you. Is this an error in PivotUtil.php when data is empty?

BrentNJ commented on Aug 31, 2022

Does this help? ErrorException Undefined array key "field1" (View: /var/www/html/resources/views/sdadmin/reports-summary.blade.php)

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError vendor/koolreport/pivot/PivotUtil.php:239

row 239 is identified as if (!$this->isRollupNodePart($nodes[$lsvi][$f])) {

stack trace

               $prevNodeN = Util::get($prevNode, $fieldN);
                if ($nodeN === null || $nodeN !== $prevNodeN) {
                    $isNodeDiff = true;
                    break;
                }
            }
            // echo "field = " . $f . "<br>";
            // echo "isNodeDiff = "; var_dump($isNodeDiff); echo "<br>";
            // echo "<br>";

            if ($isNodeDiff) {
                $lsvi = $lastSameValueIndex[$f];
                // echo "lastSameValueIndex = " . $lsvi . "<br>";
                // echo "lastSameValueIndex node value = " . $nodes[$lsvi][$f] . "<br>";
                // if ($nodes[$lsvi][$f] !== '{{all}}') {
                if (!$this->isRollupNodePart($nodes[$lsvi][$f])) {
                    // echo "set numChildren<br>";
                    $nodesInfo[$lsvi][$f]['numChildren'] = $numChildren[$f];
                    $nodesInfo[$lsvi][$f]['numLeaf'] = $numLeaf[$f];
                }
                $lastSameValueIndex[$f] = $index;
                $numChildren[$f] = 1;
                $numLeaf[$f] = 1;

                $childOrder[$f] += 1;
                $childOrders = '';
                for ($k = 0; $k <= $j; $k++) {
                    $childOrders .= ($childOrder[$fields[$k]]) . ".";
                }
                $childOrders = substr($childOrders, 0, -1); //remove last "."
                $nodesInfo[$index][$f]['childOrder'] = $childOrders;
BrentNJ commented on Aug 31, 2022

Yes data is empty

BrentNJ commented on Sep 13, 2022

Checking - any ideas?

Sebastian Morales commented on Sep 14, 2022

Thanks for your info. We have fixed this error with PivotUtil when input data is empty. It will be available in the next version of Pivot package to be released very soon. Rgds,

BrentNJ commented 3 days ago

Hi, upgraded today got passed the row grouping error now get undefined for the column

still testing with empty data ErrorException Undefined array key "field3"

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
bug

None