KoolReport's Forum

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

Adding filter in PivotMatrix #2745

Open DVBI opened this topic on on Jun 30, 2022 - 1 comments

DVBI commented on Jun 30, 2022

Hi Team,

I need to create a filter/search bar if I search with a particular row or column only it should be displayed. consider the below table, if I do search with Tier1 then only Tier1 row should be displayed... similarly for columns... can you give suggestions for integrating that?

image

Sebastian Morales commented on Jul 1, 2022

From your screenshot I assume you're using PivotMatrix. To add filters to reports with PivotMatrix pls follow the following steps:

1 . Add a form tag method post around PivotMatrix widget.

2 . Add your filter inputs (text, select, datetime, etc) to the form. For example:

<form method="post">
    <input type="text" name="contractTier" />
    <?php
        PivotMatrix::create(...);
    ?>
</form>

3 . Add this hidden input so that PivotMatrix updates upon submitting the form:

<input type='hidden' name='koolPivotUpdate' value=1 />

4 . Add param names to report, use them to do filtering in setup, and add "scope" property to PivotMatrix in report view so that it includes the filter values when changing fields, sorting, etc:

//MyReport.php:
    protected function defaultParamValues()
    {
        return array(
            "contractTier"=>...,
            ...                
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "contractTier"=>"contractTier",
            ...
        );
    }

    function setup()
    {
        // do filtering via sql query or Filter process using $this->params["contractTier"] value
        ...
    }

//MyReport.view.php:
                PivotMatrix::create(array(
                    ...
                    "scope" => [
                        "contractTier" => $this->params["contractTier"],
                        ...
                    ],

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

Pivot