KoolReport's Forum

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

CSVDataSource: Inputs > autofill MultipleSelect option field #109

Open bysystem opened this topic on on Sep 12, 2017 - 5 comments

bysystem commented on Sep 12, 2017

Dear support team,

I habe a CSV file as DataSource and I have implemented a PivotTable which works fine. I would like to implement an additional filter box where the user can search for specific fields and the result after submitting these criterias the pivottable shows only the found results from the CSV file.

In a SQL database source I do it in KoolReport as follows but I don't know how to bind the filter parameters in CSVDataSource (in this example the database field names are equal to the select fields >> filter1, filter2):

My setup:

function defaultParamValues()
{
    return array(
    "filter1" => array(),
        "filter2" => array(),
    );
}

function bindParamsToInputs()
{
    return array(
	"filter1",
	"filter2",
    );
}

Filling the select option fields:

function setup()
{
	// filter1:
	$this->src('csv_datastore')
    ->query("
		SELECT DISTINCT filter1
		FROM Reporting.DB 
		ORDER BY filter1 ASC
    ")
    ->pipe($this->dataStore("datastore_filter1"));

	// filter2
	$this->src('csv_datastore')
    ->query("
		SELECT DISTINCT filter2
		FROM Reporting.DB 
		ORDER BY filter2 ASC
    ")
    ->pipe($this->dataStore("datastore_filter1"));	

Binding the field parameters into the SQL statements as follows

	$this->src('csv_datastore')
		->query("
		SELECT filter1, filter2
		FROM Reporting.DB
		WHERE			
			:filter1 AND
			:filter2
			
	")->params(array(
		":filter1"=>$this->params["filter1"],
		":filter2"=>$this->params["filter2"]
	))

In my view php:

			<h5>Filter 1</h5>
				<?php
				Select2::create(array(
					"name"=>"filter1",
					"dataStore"=>$this->dataStore("datastore_filter1"),
					"dataBind"=>"filter1",
					"multiple"=>true,
					"attributes"=>array(
						"class"=>"form-control",
					)
				));
				?>
			</div>

			<div class="form-group" style="width:250px;margin-right:10px;">
			<h5>Filter 2</h5>
				<?php
				Select2::create(array(
					"name"=>"filter2",
					"dataStore"=>$this->dataStore("datastore_filter2"),
					"dataBind"=>"filter2",
					"multiple"=>true,
					"attributes"=>array(
						"class"=>"form-control",
					)
				));
				?>
			</div>

Any hint for me how to do the same within a CSV DataStore?

Kind regards

KoolReport commented on Sep 12, 2017

You do this:

$this->src('csv')
->pipe(new Filter(array(
    array("column_name_1","=",$this->params["filter1"]),
    array("column_name_2",">",$this->params["filter2"]),
)))
bysystem commented on Sep 12, 2017

Thx for your hint,

Unfortunately this does not exactly what I need:

  • I've embedded the pipe above (with new Filter) but still not possible to multiple choose in the corresponding field (here: product names) >> It appears "No results found!". Normaly it should be possible to show all the DISTINCT product names in the dropdown box as soon as the user beginns to type (auto-suggestion)!

Any other hint for me?

KoolReport commented on Sep 13, 2017

Oh I see,

What you have to do is to build the distinct values for filter1 and filter2 from the CSV sources, you can do it through grouping:

$source = $this->src('csv');

$source->pipe(new Group(array(
    "by"=>"filter1_field",
)))
->pipe($this->dataStore("datastore_filter1"));

$source->pipe(new Group(array(
    "by"=>"filter2_field",
)))
->pipe($this->dataStore("datastore_filter2"));

$source->pipe(new Filter(array(
    array("filter1_field","=",$this->params["filter1"]),
    array("filter2_field","=",$this->params["filter2"])
)))
->pipe(...)
... //Pipe to your Pivot here
->pipe($this->dataStore("result"));

What you have seen from above code, you have the $source which is the raw CSV data, the source will branch to pipe data to 3 different routes. The first will get distinct values for filter1, second is for filter2 and last one will be the result.

Hope that I explained well.

bysystem commented on Sep 18, 2017

Thx a lot! It works fine!

KoolReport commented on Sep 18, 2017

Great!

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
solved

Inputs