KoolReport's Forum

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

How to pass "All" option to Multiple Data Filters #1234

Open Sowmya opened this topic on on Dec 30, 2019 - 9 comments

Sowmya commented on Dec 30, 2019

Dear KoolReport Team,

I am using "Multiple Data Filters", same as your example only I implemented.

Now I have a small requirement, in your example for Empty selection you display all records, Where as my requirement is "I have to display all records when I select "All" option.

My default option should be "All" in all DataFilters.

How can I do this...

Please give me some solution.

Thanks in advance.
Sowmya commented on Dec 30, 2019

Support is there? or not?

David Winterburn commented on Dec 31, 2019

Hi Sowmya,

Unfortunately, for this you would have to retrieve data from your datasource and put it in function defaultParamValues() of your report like this:

public function defaultParamValues()
{
    $allOptions = getMyOptionsData();
    return [
        ...
        "MyParameter" => $allOptions
    ];
}

Let us know if you have any difficulty. Thanks!

Sowmya commented on Dec 31, 2019

From dataSource I can retrieve "All" option as follows...

Select2::create(array(
            "name" => "salesManger",
            "dataSource"=>$this->src('enquiry')
                          ->query("SELECT 'All'
                                   UNION ALL
                                   SELECT DISTINCT salesManger from EnquiryDataView "),
                                ));

Then how can I pass it to defaultParamValues() ?

Please give me suggestion....

Sowmya commented on Jan 2, 2020

Dear sir I changed my code , I wrote a custom function and called that function in defaultParamValues() as follows...

Select2::create(array(
            "name" => "salesManger",
            "dataSource"=>$this->src('enquiry')
                          ->query("SELECT 'All' salesManger
                                   UNION ALL
                                   SELECT DISTINCT salesManger from EnquiryDataView "),
                          ->pipe(new salesManger(function($row){
                            return $row[0];
                          }));

For this query I got the result as follows

public function defaultParamValues()
    {
        return array(
            "salesManger"=>salesManger()
          );
   }

Error:

Call to undefined function salesManger()

Sowmya commented on Jan 3, 2020

Dear Sir, Please reply as soon as possible, I have to complete this task today only.

Sowmya commented on Jan 3, 2020

Is Support working?

David Winterburn commented on Jan 6, 2020

You need to get data from your query in public function defaultParamValues() to assign them to the default "salesManger" parameter. If you don't know how to get data from your database with a query, please google it. Thanks!

Sowmya commented on Jan 6, 2020

Thank you for your response. I done changes as you specified. But no use. Here I am showing my code. Please let me know where I done mistake.

public function defaultParamValues()
    {
    	return array(
    		"salesManger"=> $this->src('enquiry')
                            ->query("SELECT 'All' as salesManger FROM EnquiryDataView"),
                                                       
    		"country"=>$this->src('enquiry')
                            ->query("SELECT 'All' as country FROM EnquiryDataView")

    	);
    }
<?php
          Select2::create(array(
            "multiple"=>true,
            "name" => "salesManger",
            "dataSource"=>$this->src('enquiry')
                          ->query("SELECT 'All' AS salesManger
                            UNION ALL
                            SELECT DISTINCT salesManger from  EnquiryDataView GROUP BY                                                  salesManger")
"attributes"=>array(
                        "class"=>"form-control"),
            ));
          ?>

David Winterburn commented on Jan 6, 2020

Hi,

This code section of your is wrong:

public function defaultParamValues()
    {
    	return array(
    		"salesManger"=> $this->src('enquiry')
                            ->query("SELECT 'All' as salesManger FROM EnquiryDataView"),
                                                       
    		"country"=>$this->src('enquiry')
                            ->query("SELECT 'All' as country FROM EnquiryDataView")

    	);
    } 

$this->src(...)->pipe(...) is used by KoolReport to set up a report's data flow. It isn't a function to get data right away. You already have a query, please google how to use a query to get data from your type of database. For example:

https://www.php.net/manual/en/mysqli.query.php

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

Inputs