KoolReport's Forum

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

Laravel and Drilldown #2047

Closed Aljaz Ketis opened this topic on on Apr 26, 2021 - 17 comments

Aljaz Ketis commented on Apr 26, 2021

I have a laravel project and i use your Koolreport Pro package and i want to display a drilldown view, so basically a amazing Card and on click I want to display a basic Table. I see that the Post Method is called, but there is a mismattch in CSRF tokens, so i googled it and found that there is an issue and how to resolve it on this forum (https://www.koolreport.com/forum/topics/1356), but it didn't work.. i need help. And another question or improvement, is it possible to add custom icon or an .svg of your own as the card icon?

Sebastian Morales commented on Apr 26, 2021

Pls open your browser's dev tool (F12), tab Network -> XHR to catch ajax request. Then perform drilldown action and see if the xhr request contains CSRF token or not?

Aljaz Ketis commented on Apr 26, 2021

It is not set, that is the source of my problem, even if I add the Ajax configuration at top, it is still not included. Why can't i incude other params and _token like you can do on PivotMatrix with:

"scope"         => array(
                    "_token"   => csrf_token(),
                    "other_params" => "example"
)
Sebastian Morales commented on Apr 27, 2021

Pls add this meta tag to your page's head and this code to your page (after jQuery link or widget render):

<meta name="csrf-token" content="<?php echo csrf_token(); ?>" />
...
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
console.log("Finished ajax setup CSRF");
</script> 

Then check your browser's dev console to see if "Finished ajax setup CSRF" is in output. Tks,

Aljaz Ketis commented on Apr 28, 2021

Yet another work-around, but how can you add additional params when the ajax call is executed, becouse I need them for other parts of the report?

Sebastian Morales commented on Apr 29, 2021

If the widgets you use don't support "scope" property, which add parameters to ajax request, you could set ajax request's default data with these javascript codes:

<script>
		// Add another data item to the global configuration
		$.ajaxSetup({
			data: {
				paramName: paramValue,
				...
			}
		});
</script>

or:

$.ajaxSetup({
  beforeSend: function(jqXHR, settings) {
    settings.data = $.extend(settings.data, {paramName: paramValue});
    return true;
  }
});
Aljaz Ketis commented on Jun 1, 2021

But i make multiple requests and each report needs different params, i dont want to send all params to each of the ajax request. This solution is really not what i was looking for.

Sebastian Morales commented on Jun 1, 2021

Oh, what prevent you from adding the necessary parameters for each ajax call? You could ouput all of a report's params to client side in its view like this and use them in your ajax calls:

    //MyReport.view.php
    ...
    <script>
        var reportParams = <?php echo json_encode($this->params); ?>; //this reportParams would variable holds all of this report's params in javascript
    </script>
Aljaz Ketis commented on Jun 1, 2021

But why, why would you do that. What if I have a section of report which is returning a File as a parameter, what if that file is 2MB big, then I need to include that 2MB file to all the Ajax requests, becouse you cannot add only the params needed inside drilldown?

Sebastian Morales commented on Jun 2, 2021

Hmm, I must have misunderstood you somewhere. Would you pls describe a specific example together with your pseudo code, what you want, and what the current problem is. Tks,

Aljaz Ketis commented on Jun 2, 2021

I want to display a blade.php view inside laravel. This page has multiple sections, one of the section is not koolreport related and is for uploading a file which works fine, now in other section I have a drilldown report rendered, so now when i want to upload a file i call post method and save it to DB, but to update the section of drilldown it is not working, because the drilldown.js wants to call POST method of the current page, which has a required field for file upload. My question now is, how can I include reports inside a bigger view and update only the Report parts not the whole page.

Sebastian Morales commented on Jun 2, 2021

I'm not sure about your point about drilldown. Pls post your report's view code where you used drilldown and other sections. Rgds,

Aljaz Ketis commented on Jun 7, 2021

Currently i have a Drilldown view in whichin we filter data inside DataTables, everything works regarding params that are used by drildown and sent within drilldown levels..but after the first drilldown.next is executed, other params specified in scope are missing, i can see that they are defined in $scope variable, but i don't know how to send them next to drilldown_params

 DrillDown::create(
                    array(
                        "name"   => "testDrillDown",
                        "title"  => " ",
                        "scope"  => array(
                            "room_types"     => $this->params["room_types"],
                            "users"          => $this->params["users"],
                            "space_statuses" => $this->params["space_statuses"],
                            "report_type"    => $this->params["report_type"],
                            "facility"       => $this->params["facility"],
                            "date"           => $this->params["date"],
                        ),
                        "levels" => array(
                            array(
                                //Level 1: Show all per room status
                                "title"   => "per Status",
                                "content" => function ($params, $scope) {
                                    $params = json_encode($scope);
                                    DataTables::create(
                                        array(
                                            "dataSource"   => $this->getTableQuery("start_space_status"),
                                            "options"      => array(
                                                "searching" => true,
                                                "select"    => true,
                                            ),
                                            "clientEvents" => array(
                                                "select" => "function(e,dt,type,indexes){
                                                     var data = dt.rows( indexes ).data()[0];
                                                     testDrillDown.next({status_drill:data[0]})
                                                }",
                                            ),
                                        )
                                    );
                                },
                            ),
array(
                    //Level 2: Show all with status per room type
                    "title"   => function ($params, $scope) {
                        return "Status - " . $params["status_drill"];
                    },
                    "content" => function ($params, $scope) {
                        DataTables::create(
                            array(
                                "dataSource"   => $this->getTableQuery(
                                    "start_space_status, room_type",
                                    "AND start_space_status = '{$params['status_drill']}'"
                                ),
                                "options"      => array(
                                    "searching" => true,
                                    "select"    => true,
                                ),
                                "clientEvents" => array(
                                    "select" => "function(e,dt,type,indexes){
                                                     var data = dt.rows( indexes ).data()[0];
                                                     testDrillDown.next({room_type_drill: data[0]});
                                                }",
                                ),
                            )
                        );
                    },
                )
   )));
Aljaz Ketis commented on Jun 8, 2021

it been a few days..i really need a fix for that

Sebastian Morales commented on Jun 9, 2021

Pls try this:

    <script>
        var reportParams = <?php echo json_encode($this->params); ?>
    </script>
    <?php
                            ...
                            testDrillDown.next({
                                status_drill:data[0]},
                                room_types: reportParams.room_types,
                                users: reportParams.users,
                                space_statuses: reportParams.space_statuses,
                                report_type: reportParams.report_type,
                                facility: reportParams.facility,
                                date: reportParams.date
                            })

Let us know how it works for you. Tks,

Aljaz Ketis commented on Jun 9, 2021

The data is send inside testDrillDown, but I want to sent them as params like on picture, becouse I set this params as params of the report, which is now missing after update.

This is how it is currently sending:

This is how i want to send its data:

Sebastian Morales commented on Jun 9, 2021

Unfortunately, at the moment drilldown has not had option to attach additional data to the first level of post request. However, if you still want to bind your params to drilldown's request params you could try this code in your report's bindParamsToInputs method:

    //MyReport.php
    protected function bindParamsToInputs()
    {
        if (isset($_POST["testDrillDown"]["currentLevel"][1])) {
            $drillDownLevelParams = $_POST["testDrillDown"]["currentLevel"][1];
            foreach ($drillDownLevelParams as $param => $value) 
                $_POST[$param] = $value;
        }
        return array(...);

You could var_dump($_POST["testDrillDown"]) to get a clearer view of the additional params' structure. Rgds,

Aljaz Ketis commented on Jun 11, 2021

It is not ideal but it works thank you. Can you notify me when any changes are made regarding this?

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
help needed

DrillDown