KoolReport's Forum

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

Error in "DataTable.tpl.php" for KoolReport.helper being undefined #3428

Closed Nick Mason opened this topic on 5 days ago - 3 comments

Nick Mason commented 5 days ago

Hi, All :)

I want to report an error I've come across today while trying to use DataTable.

I currently use koolreport/datagrid@8.0.1 and get the following error when I use DataTable:

TypeError: Cannot read properties of undefined (reading 'ConvertToClientFunction'

at my-own-report:2233:35
at KoolReport.js:105:25
at Array.forEach (<anonymous>)
at Object.checkScriptsAndCallback (KoolReport.js:102:20)
at Object.onScriptLoaded (KoolReport.js:88:14)

I think KoolReport object in DataTables.tpl.php:249 in the following does not have helper property, thereby calling ConvertToClientFunction from it causes error.

<?php } else { ?>

<script type="text/javascript">
    KoolReport.widget.init(
        <?php echo json_encode($this->getResources()); ?>,
        function() {
            <?php $this->clientSideBeforeInit(); ?>

            var name = '<?php echo $uniqueId; ?>';
            var dtOptions = <?php echo ($this->options == array()) ? "" : Util::jsonEncode($this->options); ?>;
            var fastRender = <?php echo $this->fastRender ? 1 : 0; ?>;
            if (fastRender) {
                var dataRows = <?php echo json_encode($this->dataRows); ?>;
                dtOptions.data = dataRows;
                // <?php echo $uniqueId; ?>_data.dataRows = dataRows;
            }
            window[name + '_state'] = {};
            // >>> Here <<<
            KoolReport.helper.ConvertToClientFunction.call(dtOptions, dtOptions);
            // >>> Here <<<
            var dt = window[name] = $('#' + name).DataTable(dtOptions);
            dt.registerEvent = dt.on;

            var <?php echo $uniqueId; ?>_data = {
                name: '<?php echo $uniqueId; ?>',
                id: '<?php echo $uniqueId; ?>',
                searchOnEnter: <?php echo $this->searchOnEnter ? 1 : 0; ?>,
                searchMode: <?php echo json_encode($this->searchMode); ?>,
                serverSide: <?php echo $this->serverSide ? 1 : 0; ?>,
                serverSideInstantSearch: <?php echo $this->serverSideInstantSearch ? 1 : 0; ?>,
                overrideSearchInput: <?php echo $this->overrideSearchInput ? 1 : 0; ?>,
                rowDetailData: dtOptions.rowDetailData,
                showColumnKeys: <?php echo json_encode($showColumnKeys); ?>,
                columns: <?php echo json_encode($this->columns); ?>,
                editButtons: <?php echo json_encode($this->editButtons); ?>,
                editUrl: '<?php echo Util::get($this->params, "editUrl"); ?>',
                fastRender: fastRender,
                rowDetailIcon: <?php echo $this->rowDetailIcon ? 1 : 0; ?>,
                rowDetailSelector: '<?php echo $this->rowDetailSelector; ?>',
                clientRowSpanColumns: <?php echo json_encode($this->clientRowSpanColumns); ?>,
                themeBase: '<?php echo $this->getThemeBase(); ?>',
            };
            <?php echo $uniqueId; ?>_data.rawData = <?php echo json_encode($this->rawData); ?>;
            KR<?php echo $uniqueId; ?> = KoolReport.KRDataTables.create(
                <?php echo $uniqueId; ?>_data);

            <?php if ($this->clientEvents) {
                foreach ($this->clientEvents as $eventName => $function) { ?>
                    dt.on("<?php echo $eventName; ?>", <?php echo $function; ?>);
            <?php }
            } ?>

            <?php $this->clientSideReady(); ?>
        }
    );
</script>

<?php } ?>

It happens even when I use Datatable in a very simple case as it follows:

    DataTables::create(
        [
            "dataSource" => $data,
        ]
    );

So, it should be fairly easy to reproduce this error.

Once I downgrade a version of koolreport/datagrid to "7.9.1", everything start working again without the above error.

Thank you :)

Sebastian Morales commented 5 days ago

Pls update your koolreport/core package as well for the newer version of koolreport/datagrid to work with. If you have any difficulty let us know.

Nick Mason commented 4 days ago

Hi, Sebastian.

I've just checked my composer.lock and make sure to do 'composer update' as well to get the latest version of everything as follows:

        "require": {
            "koolreport/amazing": "2.4.2",
            "koolreport/apexcharts": "1.1.1",
            "koolreport/appstack": "1.2.1",
            "koolreport/barcode": "2.1.0||3.1.1",
            "koolreport/blade": "1.0.2",
            "koolreport/bootstrap3": "1.1.0",
            "koolreport/bootstrap4": "1.5.1",
            "koolreport/bootstrap5": "1.0.0",
            "koolreport/cache": "1.2.0",
            "koolreport/chartjs": "3.3.1",
            "koolreport/charttable": "1.4.0",
            "koolreport/cleandata": "1.6.1",
            "koolreport/cloudexport": "4.2.1",
            "koolreport/codeigniter": "1.8.0",
            "koolreport/core": "6.6.1",
            "koolreport/cube": "3.5.1",
            "koolreport/d3": "1.7.1",
            "koolreport/datagrid": "8.0.1",
            "koolreport/drilldown": "3.8.1",
            "koolreport/excel": "11.0.1",
            "koolreport/export": "5.5.0",
            "koolreport/inputs": "6.5.0",
            "koolreport/instant": "3.7.0",
            "koolreport/laravel": "2.1.0",
            "koolreport/morris_chart": "3.0.1",
            "koolreport/pivot": "9.4.0",
            "koolreport/querybuilder": "3.4.1",
            "koolreport/sparklines": "1.5.0",
            "koolreport/statistics": "1.2.0",
            "koolreport/visualquery": "2.7.1",
            "koolreport/yii2": "1.0.0",
            "php": ">=5.4"
        },

And I still get the same error

Nick Mason commented 3 days ago

Hi, Sebastian.

I've found out that it's just a caching issue on my end and now it's working once a cache is cleared up :)

Thank you :)

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

DataGrid